Reloading nested modules

Andy Jewell andy at wild-flower.co.uk
Sun Jul 13 23:33:59 CEST 2003


Does anyone know of a way to dynamically reload all the imported modules of a 
client module?

I'm writing a program that I have broken down into quite a few submodules, and 
the 'configuration' is done with modules too.  As I am developing the app, I 
need to test bits and pieces here and there.  This is what I currently do:

In each module, I have a section, just after the main imports like so:


-----------8<-----------
# normal imports:

from ooby import squibble,dibble
import dooby
import doo

# reloads for debugging

import ooby # create a reference to ooby so we can reload it
reload(ooby)
reload(dooby)
reload(doo)

# main module code begins...
-----------8<-----------


The debugging imports of course will be dropped when the program is stable.  

I also often find myself doing similar stuff from the command-line, like:

reload(ooby.oojar); reload(ooby.dibble); reload(ooby);  ooby.somefunc(.....)

I just wondered if anyone had develped a better 'spell' or even a small script 
that uses some clever intorspecton hack, before I go and start trying to 
reinvent the wheel...

-andyj





More information about the Python-list mailing list