By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,114 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,114 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 9, 9:06*am, "gbin,Zhou" <scutee...@gmail.comwrote:
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.
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/pyt...ry/022526.html

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

Good luck!

Mike
Jun 27 '08 #2

P: n/a
En Fri, 09 May 2008 11:06:49 -0300, gbin,Zhou <sc*******@gmail.comescribió:
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?
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

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.