Take the following code example:
File package1/__init__.py
:
from moduleB import foo
print moduleB.__name__
File package1/moduleB.py
:
def foo(): pass
Then from the current directory:
>>> import package1
package1.moduleB
This code works in CPython. What surprises me about it is that the from ... import
in __init__.py
statement makes the moduleB
name visible. According to Python documentation, this should not be the case:
The from form does not bind the module name
Could someone please explain why CPython works that way? Is there any documentation describing this in detail?