python/dna/utils.py
def dynamic_import(mod_path, obj_name=None):
    ''' Take a string and return the corresponding module '''
    try:
        module = __import__(mod_path, fromlist=['whatever'])
    except ImportError, error:
        raise errors.DynamicImportFailed(
            module='.'.join([mod_path, obj_name]), reason=error)
    # Make sure we're up-to-date
    reload(module)

    if obj_name is None:
        obj = module
    elif hasattr(module, obj_name):
        obj = getattr(module, obj_name)
    else:
        raise errors.DynamicImportFailed(
            module='.'.join([mod_path, obj_name]),
            reason='module {} has no attribute {}'.
                   format(module.__name__, obj_name))
        return None

    return obj
def dynamic_import(mod_path, obj_name=None):
    ''' Take a string and return the corresponding module '''
    try:
        module = __import__(mod_path, fromlist=['whatever'])
    except ImportError, error:
        raise errors.DynamicImportFailed(
            module='.'.join([mod_path, obj_name]), reason=error)
    # Make sure we're up-to-date
    reload(module)

    if obj_name is None:
        obj = module
    elif hasattr(module, obj_name):
        obj = getattr(module, obj_name)
    else:
        raise errors.DynamicImportFailed(
            module='.'.join([mod_path, obj_name]),
            reason='module {} has no attribute {}'.
                   format(module.__name__, obj_name))
        return None

    return obj
Take a string and return the corresponding module