@contextlib.contextmanager
def uncache(*names):
 for name in names:
  if (name in ('sys', 'marshal', 'imp')):
   raise ValueError('cannot uncache {0} as it will break _importlib'.format(name))
  try:
   del sys.modules[name]
  except KeyError:
   pass
 try:
  (yield)
 finally:
  for name in names:
   try:
    del sys.modules[name]
   except KeyError:
    pass

@ contextlib . contextmanager def uncache ( * names ) : for name in names : if ( name in ( 'sys' , 'marshal' , 'imp' ) ) : raise ValueError ( 'cannot uncache {0} as it will break _importlib' . format ( name ) ) try : del sys . modules [ name ] except KeyError : pass try : ( yield ) finally : for name in names : try : del sys . modules [ name ] except KeyError : pass
uncache a module from sys .