Reloading a module

Tom bondpaper at earthlink.net
Mon Sep 30 22:16:15 EDT 2002


In article <anastb$h2s$1 at peabody.colorado.edu>,
 Fernando Perez <fperez528 at yahoo.com> wrote:

> Tom wrote:
> 
> > 
> > I'm developing some python mini applets on a Mac (using os 9 and the
> > 2.1.1 Python IDE), and I've found it impossible to delete and/or reload
> > a module after making changes to the code during the
> > debugging/verification process. Is there an easy and/or effective way to
> > do this? If I execute:
> > 
> > del mymodule
> > 
> > and then execute a print dir(mymodule), it shows up as nonexistent.
> > Then, when I execute:
> > 
> > import mymodule
> > 
> > followed by a print dir(mymodule), the changes do not show up.
> 
> In [1]: reload?
> Type:           builtin_function_or_method
> Base Class:     <type 'builtin_function_or_method'>
> String Form:    <built-in function reload>
> Namespace:      Python builtin
> Docstring:
>     reload(module) -> module
> 
>     Reload the module.  The module must have been successfully imported 
> before.
> 
> cheers,
> 
> f.

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.

Thanks,

Tom



More information about the Python-list mailing list