On 03/29/2011 08:14 PM, monkeys paw wrote:
How do i delete a module namespace once it has been imported?

I use

import banner

Then i make a modification to banner.py. When i import it again,
the new changes are not reflected. Is there a global variable i can
modify?

Delete it from sys.modules:

>>> file('foo.py', 'w').write('x = 42\n')
>>> import foo
>>> foo.x
42
>>> del foo
>>> import sys
>>> del sys.modules['foo']
>>> file('foo.py', 'w').write('x = 999\n')
>>> import foo
>>> foo.x
999

Beware that if you still have old references to the module, they don't get refreshed.

-tkc


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to