
import json
import sys
from db import dbManager


# insert an organism into a database table
def insert(args):
    if hasattr(args, 'json'):
        data = json.loads(args.json)
    else:
        data = json.load(args.infile)
    with dbManager('config/db.cfg') as db:
        for org in data:
            db.insertOrganism(org, args.dbname, args.job)
    return data


import json
import sys
from db import dbManager


# insert an organism into a database table
def insert(args):
    try:
        data = json.loads(args.json)
    except AttributeError:
        data = json.load(args.infile)
    with dbManager('config/db.cfg') as db:
        for org in data:
            db.insertOrganism(org, args.dbname, args.job)
    return data

Use exception block instead as exception was still being thrown.
Use exception block instead as exception was still being thrown.

  
  import json
  import sys
  from db import dbManager
  
  
  # insert an organism into a database table
  def insert(args):
-     if hasattr(args, 'json'):
+     try:
          data = json.loads(args.json)
-     else:
+     except AttributeError:
          data = json.load(args.infile)
      with dbManager('config/db.cfg') as db:
          for org in data:
              db.insertOrganism(org, args.dbname, args.job)
      return data
  
Use exception block instead as exception was still being thrown.
## Code Before:

import json
import sys
from db import dbManager


# insert an organism into a database table
def insert(args):
    if hasattr(args, 'json'):
        data = json.loads(args.json)
    else:
        data = json.load(args.infile)
    with dbManager('config/db.cfg') as db:
        for org in data:
            db.insertOrganism(org, args.dbname, args.job)
    return data

## Instruction:
Use exception block instead as exception was still being thrown.
## Code After:

import json
import sys
from db import dbManager


# insert an organism into a database table
def insert(args):
    try:
        data = json.loads(args.json)
    except AttributeError:
        data = json.load(args.infile)
    with dbManager('config/db.cfg') as db:
        for org in data:
            db.insertOrganism(org, args.dbname, args.job)
    return data
