[issue19812] reload() by symbol name

STINNER Victor report at bugs.python.org
Wed Nov 27 12:19:52 CET 2013


STINNER Victor added the comment:

You can retrieve the module using sys.modules[symbol.__module__].

Example:

>>> from os import environ as ENV
>>> import imp, sys
>>> imp.reload(sys.modules[ENV.__module__])
<module 'os' from '/usr/lib64/python2.7/os.pyc'>
>>> _.environ is ENV
False

But if you import symbols instead of modules, symbols will still point to the old version of the module. This explain the final "False" result.

You should import modules if you want to play with reload().

I prefer to exit and restart Python instead of playing with reload, I see it as a hack which has many issues like "_.environ is ENV" returning False.

----------
nosy: +haypo

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19812>
_______________________________________


More information about the Python-bugs-list mailing list