reload fails if module not in sys.path
fredrik at pythonware.com
Fri Oct 21 08:29:50 CEST 2005
Lonnie Princehouse wrote:
> Maybe it could fall back to module.__file__ if the module isn't found
> in sys.path??
> ... or reload could just take an optional path parameter...
> Or perhaps I'm the only one who thinks this is silly:
> >>> my_module = imp.load_module(module_name, *imp.find_module(module_name,path))
> >>> reload(my_module)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> ImportError: No module named whatever
load_module doesn't do everything that import does.
> I guess I could just deal with this by fiddling with sys.path or using
> imp.load_module again, but.. um.. I like to complain. ;-)
> The context here is that I'm loading user-defined modules as plugins,
> and I don't want to keep the plugin directory in sys.path because of
> potential module name conflicts.
so add the plugin-directory to the front of sys.path temporarily,
and remove it after you've imported the plugins. (this also allows
the plugin writers to split their plugins over multiple modules,
something that can often be quite nice)
More information about the Python-list