A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-March/043378.html below:

[Python-Dev] unexpected reload() behavior

[Python-Dev] unexpected reload() behaviorGuido van Rossum guido at python.org
Sat Mar 20 16:29:35 EST 2004
> 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/)

More information about the Python-Dev mailing list

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