def import_submodule(mod, subname, fullname):
 global found_now
 if ((fullname in found_now) and (fullname in sys.modules)):
  m = sys.modules[fullname]
 else:
  print ('Reloading', fullname)
  found_now[fullname] = 1
  oldm = sys.modules.get(fullname, None)
  if (mod is None):
   path = None
  elif hasattr(mod, '__path__'):
   path = mod.__path__
  else:
   return None
  try:
   with replace_import_hook(original_import):
    (fp, filename, stuff) = imp.find_module(subname, path)
  except ImportError:
   return None
  try:
   m = imp.load_module(fullname, fp, filename, stuff)
  except:
   if oldm:
    sys.modules[fullname] = oldm
   raise
  finally:
   if fp:
    fp.close()
  add_submodule(mod, m, fullname, subname)
 return m

def import_submodule ( mod , subname , fullname ) : global found_now if ( ( fullname in found_now ) and ( fullname in sys . modules ) ) : m = sys . modules [ fullname ] else : print ( 'Reloading' , fullname ) found_now [ fullname ] = 1 oldm = sys . modules . get ( fullname , None ) if ( mod is None ) : path = None elif hasattr ( mod , '__path__' ) : path = mod . __path__ else : return None try : with replace_import_hook ( original_import ) : ( fp , filename , stuff ) = imp . find_module ( subname , path ) except ImportError : return None try : m = imp . load_module ( fullname , fp , filename , stuff ) except : if oldm : sys . modules [ fullname ] = oldm raise finally : if fp : fp . close ( ) add_submodule ( mod , m , fullname , subname ) return m
m = import_submodule .