dynamic modules?

Michael Hudson mwh21 at cam.ac.uk
Fri Nov 26 08:49:11 EST 1999


"Adrian Eyre" <a.eyre at optichrome.com> writes:

> > Is there a chance to write modules I can dynamically change? I tried
> > reload(), but thats not working because I can't reload modules imported
> > with 'from XXX import *'.
> 
> # Reload any/all modules (N.B. untested)
> import sys
> 
> def reloadAll():
>     for mod in sys.modules.keys():
>         reloadModule(mod)
> 
> def reloadModule(name):
>     reload(sys.modules[name])

equivalently:

def reloadAll():
    for mod in sys.modules.values():
        reload(mod)

Doesn't cope with "from <...> import *" though; another reason not to
use that construct.

Cheers,
Michael




More information about the Python-list mailing list