def _import_by_name(name):
 try:
  name_parts = name.split('.')
  modname = '.'.join(name_parts[:(-1)])
  if modname:
   try:
    __import__(modname)
    mod = sys.modules[modname]
    return (getattr(mod, name_parts[(-1)]), mod)
   except (ImportError, IndexError, AttributeError):
    pass
  last_j = 0
  modname = None
  for j in reversed(range(1, (len(name_parts) + 1))):
   last_j = j
   modname = '.'.join(name_parts[:j])
   try:
    __import__(modname)
   except ImportError:
    continue
   if (modname in sys.modules):
    break
  if (last_j < len(name_parts)):
   parent = None
   obj = sys.modules[modname]
   for obj_name in name_parts[last_j:]:
    parent = obj
    obj = getattr(obj, obj_name)
   return (obj, parent)
  else:
   return (sys.modules[modname], None)
 except (ValueError, ImportError, AttributeError, KeyError) as e:
  raise ImportError(*e.args)

def _import_by_name ( name ) : try : name_parts = name . split ( '.' ) modname = '.' . join ( name_parts [ : ( - 1 ) ] ) if modname : try : __import__ ( modname ) mod = sys . modules [ modname ] return ( getattr ( mod , name_parts [ ( - 1 ) ] ) , mod ) except ( ImportError , IndexError , AttributeError ) : pass last_j = 0 modname = None for j in reversed ( range ( 1 , ( len ( name_parts ) + 1 ) ) ) : last_j = j modname = '.' . join ( name_parts [ : j ] ) try : __import__ ( modname ) except ImportError : continue if ( modname in sys . modules ) : break if ( last_j < len ( name_parts ) ) : parent = None obj = sys . modules [ modname ] for obj_name in name_parts [ last_j : ] : parent = obj obj = getattr ( obj , obj_name ) return ( obj , parent ) else : return ( sys . modules [ modname ] , None ) except ( ValueError , ImportError , AttributeError , KeyError ) as e : raise ImportError ( * e . args )
import a python object given its full name .