[Tutor] Confusion regarding the 'from' statement

Peter Otten __peter__ at web.de
Wed Aug 15 19:27:38 CEST 2012


Mazhar Hussain wrote:

> thanks alot for the help, was really confused with this. 

> Well what ure
> trying to say is that even when a module object is deleted from the
> global namespace of a module, a reference of it is still present in
> the sys.modules dict? 

Yes, adding the reference to the sys.modules cache is an integral part of 
the import.

> that means every object refers to its own module
> in the sys.modules dict?

No, every function has a reference to the enclosing module's global 
namespace where it looks up (global) names. As long as the module isn't 
garbage-collected these names refer to meaningful values.

The module isn't garbage-collected as long as there is at least one 
reference, and for modules that occur only in a

from mymodule import ...

statement that reference is sys.modules["mymodule"].



More information about the Tutor mailing list