delete namespaces
Tim Chase
python.list at tim.thechases.com
Tue Mar 29 21:41:28 EDT 2011
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
More information about the Python-list
mailing list