Why can you reference an imported module using the importing module in python
- by noam
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)?