Reloading a module

Fernando Pérez fperez528 at yahoo.com
Mon Sep 30 22:58:43 EDT 2002


Tom wrote:

> I wish it were that simple. I've used reload(module) many times, each
> time hoping that it would do what the documentation says it will do.
> I've tested it by adding a simple variable to my module, watching to see
> if it shows up in the new import, but it never does. I noticed also that
> sometimes it reloads from the .pyc file, and if the reload happens
> before the .pyc file is updated with the new changes, the changes won't
> be available. Even if I force a reload from the updated .py file by
> deleting .pyc file, it still retains the old code. I'm at a loss to
> understand what's going on.

True. I actually don't rely on reload almost ever. I instead tend to use a 
cooked-up version of execfile() for this, or deep_reload. The former is 
available under ipython as @run, the latter as dreload(). Using @run works ok 
only for top-level stuff, of course. dreload() is pretty good but still can 
fail in certain cases.

You may want to give them a try.

Cheers,

f.



More information about the Python-list mailing list