Reloading nested modules

Greg Fortune lists at gregfortune.com
Mon Jul 14 15:01:54 EDT 2003


I've wondered about the same problem and considered that as a solution, but
never tested it.  I assume that *wouldn't* rebind all of the imports that
have already happened..  ie, I think the references to the old copies of
the modules would hang around even though new ones have been imported.

Regardless, the scoping doesn't work so an attempt to reload the embedded
module assumes it is available in local scope and fails.  Again, that would
lead me to believe my first statement is true, but when I tested just now,
I got no further than the scoping problem...

I've been intended to write something that will take a module name and
rebind it in all namespaces that have it currently, but haven't got around
to it.  If I ever do, I'll post it here :)

Greg

Martin v. Löwis wrote:

> Andy Jewell <andy at wild-flower.co.uk> writes:
> 
>> Does anyone know of a way to dynamically reload all the imported
>> modules of a client module?
> 
> You could iterate over sys.modules and invoke reload for all of them.
> 
> Regards,
> Martin





More information about the Python-list mailing list