dynamic modules?

Adrian Eyre a.eyre at optichrome.com
Fri Nov 26 06:08:34 EST 1999


> 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])

> The next problem is, if I can reload all modules, I have to rebuild the
> objects instanced from classes in the reloaded modules, but that should
> be manageable.

Possible. Tricky to automate though.

> Another problem with this: Can I destroy an object without deleting all
> references?

No. The object's d'tor is not called until the last reference is removed.

--------------------------------------------
Adrian Eyre <mailto:a.eyre at optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233  Fax: +44 1483 760 644
http://www.optichrome.com 
--------------------------------------------





More information about the Python-list mailing list