> 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? Intentional. A module's __dict__ is not emptied when the reloaded module is executed. This allows code like this (which I have written) that preserves a cache across relaod() calls: try: cache except NameError: cache = {} --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4