def cleanup_sys_modules(directories):
 cleaned = []
 for (modname, module) in list(sys.modules.items()):
  modfile = getattr(module, '__file__', None)
  if modfile:
   for directory in directories:
    if modfile.startswith(directory):
     cleaned.append(modname)
     del sys.modules[modname]
     break
 return cleaned

def cleanup_sys_modules ( directories ) : cleaned = [ ] for ( modname , module ) in list ( sys . modules . items ( ) ) : modfile = getattr ( module , '__file__' , None ) if modfile : for directory in directories : if modfile . startswith ( directory ) : cleaned . append ( modname ) del sys . modules [ modname ] break return cleaned
remove submodules of directories from sys .