Why can you reference an imported module using the importing module in python

Posted by noam on Stack Overflow See other posts from Stack Overflow or by noam
Published on 2010-03-09T04:43:07Z Indexed on 2010/03/09 4:51 UTC
Read the original article Hit count: 414

Filed under:
|
|
|

I am trying to understand why any import can be referenced using the importing module, e.g

#module master.py
import slave

and then

>>>import master
>>>print master.slave

gives <module 'slave' from 'C:\Documents and Settings....'>

What is the purpose of the feature? I can see how it can be helpful in a package's __init__.py file, but nothing else. Is it a side effect of the fact that every import is added to the module's namespace and that the module's namespace is visible from the outside? If so, why didn't they make an exception with data imported from other modules (e.g don't show it as part of the module's namespace for other modules)?

© Stack Overflow or respective owner

Related posts about python

Related posts about import