def walk_modules(path):
 mods = []
 mod = import_module(path)
 mods.append(mod)
 if hasattr(mod, '__path__'):
  for (_, subpath, ispkg) in iter_modules(mod.__path__):
   fullpath = ((path + '.') + subpath)
   if ispkg:
    mods += walk_modules(fullpath)
   else:
    submod = import_module(fullpath)
    mods.append(submod)
 return mods

def walk_modules ( path ) : mods = [ ] mod = import_module ( path ) mods . append ( mod ) if hasattr ( mod , '__path__' ) : for ( _ , subpath , ispkg ) in iter_modules ( mod . __path__ ) : fullpath = ( ( path + '.' ) + subpath ) if ispkg : mods += walk_modules ( fullpath ) else : submod = import_module ( fullpath ) mods . append ( submod ) return mods
loads a module and all its submodules from the given module path and returns them .