[Python-Dev] unexpected reload() behavior (original) (raw)

Skip Montanaro skip at pobox.com
Sun Mar 21 11:16:36 EST 2004


>> It seems counterintuitive to me that reloadtst.b should still be
>> defined.  Is that behavior intention or accidental?

Guido> Intentional.  A module's __dict__ is not emptied when the
Guido> reloaded module is executed.  This allows code like this (which I
Guido> have written) that preserves a cache across relaod() calls:

Guido>     try:
Guido>         cache
Guido>     except NameError:
Guido>         cache = {}

Thanks. I saw that in the doc shortly after posting. I hope you don't mind that I just added that example to the doc.

Skip



More information about the Python-Dev mailing list