468,234 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,234 developers. It's quick & easy.

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

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
2 3334
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
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.

Similar topics

2 posts views Thread by Bob Tinsman | last post: by
5 posts views Thread by mkaushik | last post: by
3 posts views Thread by Daniel Mark | last post: by
4 posts views Thread by eqq2002 | last post: by
30 posts views Thread by Medvedev | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.