473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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 3661
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: gary | last post by:
Hi, We all know the below codes are dangerous: { int *p = new int; delete p; delete p; } And we also know the compilers do not delete p if p==NULL. So why compilers do not "p = NULL"...
8
by: John Baker | last post by:
Hi: Access 2000 W98! I have a table with numerous records in it, and am attempting to delete certain records that have been selected from it. These are selected based on the ID number in a...
2
by: Bob Tinsman | last post by:
This problem shows up in Firefox 1.5.0.1 and Rhino 1.6R2. I've found that if I have an XML node expression that ends in a filter, I can't use it with the delete operator. In the following...
5
by: mkaushik | last post by:
Hi everyone, Im just starting out with C++, and am curious to know how "delete <pointer>", knows about the number of memory locations to free. I read somewhere that delete frees up space...
3
by: Daniel Mark | last post by:
Hello all: I am looking the sample code posted on PIL website http://www.pythonware.com/library/pil/handbook/imagedraw.htm ################################################ <<Draw a Grey Cross...
4
by: eqq2002 | last post by:
The below is my code and my compiler is vc++: #include <iostream> using namespace std; int main(){ int *pint = new int(1024); cout << "The initialized value of *pint is " <<...
1
by: MorgyTheMole | last post by:
I have a base class: class A { protected: static void* operator new (size_t size); void operator delete (void *p); public: void Delete(); }
30
by: Medvedev | last post by:
i see serveral source codes , and i found they almost only use "new" and "delete" keywords to make they object. Why should i do that , and as i know the object is going to be destroy by itself at...
3
by: tvnaidu | last post by:
I compiled tinyxml files (.cpp files) and when I am linking to create final exe in Linux, I am getting lot of errors saying "undefiend reference" to "operator new" and "delete", any idea?. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.