def dynamic_import(import_string):
 lastdot = import_string.rfind('.')
 if (lastdot == (-1)):
  return __import__(import_string, {}, {}, [])
 (module_name, attr) = (import_string[:lastdot], import_string[(lastdot + 1):])
 parent_module = __import__(module_name, {}, {}, [attr])
 return getattr(parent_module, attr)

def dynamic_import ( import_string ) : lastdot = import_string . rfind ( '.' ) if ( lastdot == ( - 1 ) ) : return __import__ ( import_string , { } , { } , [ ] ) ( module_name , attr ) = ( import_string [ : lastdot ] , import_string [ ( lastdot + 1 ) : ] ) parent_module = __import__ ( module_name , { } , { } , [ attr ] ) return getattr ( parent_module , attr )
dynamically import a module or object .