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

Skip Montanaro skip at pobox.com
Fri Mar 19 10:03:55 EST 2004


In working on the doc change for <http://python.org/sf/919099> I came across this statement:

The names in the module namespace are updated to point to any new or
changed objects. Names of unchanged objects, or of objects no longer
present in the new module, remain pointing at the old objects.

(The bit about names of unchanged objects still pointing to the old objects is incorrect. I'll fix that.)

Not believing that old objects remained after the reload() I wrote a short test:

a = 5
b = 7
c = (1,2,3)

imported it, modified it to

a = 9
c = (1,2,3)

then reloaded it. I was surprised to find that reloadtst.b did indeed still exist:

>>> import reloadtst
>>> dir(reloadtst)
>>> dir(reloadtst)
['__builtins__', '__doc__', '__file__', '__name__', 'a', 'b', 'c']
>>> # edit reloadtst.py
...
>>> reload(reloadtst)
<module 'reloadtst' from 'reloadtst.py'>
>>> dir(reloadtst)
['__builtins__', '__doc__', '__file__', '__name__', 'a', 'b', 'c']

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

Skip



More information about the Python-Dev mailing list