Reloading modules

Michael Hudson mwh at
Thu Feb 21 12:43:24 CET 2002

Jeff Davis <jdavis at> writes:

> Is there a way to say that all calls to import should check for a newer 
> version, if a newer one exists then completely drop the old one and import 
> the new one?

An import hook could do this.  Wouldn't be trivial to write, but not
too hard, either.

> I am aware of the reload() function, but it has enough caveats that it 
> always leaves lingering questions.

Um, if reload() has problems, how would the above be much better?  I
suppose it would get round the having-to-reload-submodules problem.

> I usually end up just stopping and restarting the interpreter, which
> slows development/debugging. I would just like to be sure that any
> time after I import a module, I am using the newest version
> available at the time of import.  

> I am also unsure as to whether
> modules imported within a reloaded module are also reloaded.

Not if you call reload() on it, no.  The above-alluded to import hook
would solve this problem.


  ARTHUR:  Don't ask me how it works or I'll start to whimper.
                   -- The Hitch-Hikers Guide to the Galaxy, Episode 11

More information about the Python-list mailing list