Reloading a module

Mark Jackson mjackson at
Tue Oct 1 13:52:58 CEST 2002

Tom <bondpaper at> writes:

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

See the language reference on reload, at, in

    When a module is reloaded, its dictionary (containing the module's
    global variables) is retained. Redefinitions of names will override the
    old definitions, so this is generally not a problem. If the new version
    of a module does not define a name that was defined by the old version,
    the old definition remains. This feature can be used to the module's
    advantage if it maintains a global table or cache of objects -- with a
    try statement it can test for the table's presence and skip its
    initialization if desired.

If you want to remove a name and test the result with reload:  don't
remove the defining line, just follow it immediately with del.

Mark Jackson -
    How can anyone be expected to govern a country with two
    hundred and forty-six cheeses?  - Charles de Gaulle

More information about the Python-list mailing list