Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I "delete" the namespace of a module that i import?

57 views
Skip to first unread message

gbin,Zhou

unread,
May 9, 2008, 10:06:49 AM5/9/08
to
Hi,all.
I see from "http://docs.python.org/tut/node11.html" that "Name
spaces are created at different moments and have different lifetimes.
The namespace containing the built-in names is created when the Python
interpreter starts up, and is never deleted. The global namespace for
a module is created when the module definition is read in; normally,
module namespaces also last until the interpreter quits."
So can I "delete" the namespace of a module that i import?
thanks.

Mike Driscoll

unread,
May 9, 2008, 10:25:40 AM5/9/08
to

I did some searching and haven't found much. The closest I've found so
far is this old thread:

http://mail.python.org/pipermail/python-list/2000-February/022526.html

You might look at IDLE's code to see what it does when you tell it to
"restart" too.

Good luck!

Mike

Gabriel Genellina

unread,
May 10, 2008, 10:07:58 PM5/10/08
to pytho...@python.org

You can make Python "forget" a module by removing it from sys.modules; that way, next time you import it, Python will load it again from file.
Or you can use the built-in reload() function to get a "fresh" copy from file.
But any references to objects in the old module will still refer to the old objects (that means, by example, that existing instances of classes defined in the module will still refer to the old definition)

--
Gabriel Genellina

0 new messages