Reloading nested modules

Andy Jewell andy at
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:

# 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

# main module code begins...

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...


More information about the Python-list mailing list