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

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat May 10 22:07:58 EDT 2008


En Fri, 09 May 2008 11:06:49 -0300, gbin,Zhou <scuteezgb at gmail.com> escribió:

>    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




More information about the Python-list mailing list