Yes, the package.__init__
module will have access to the name module
:
$ mkdir package
$ touch package/__init__.py
$ touch package/module.py
$ python
Python 2.7.5 (default, Oct 28 2013, 20:45:48)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from package import module
>>> import sys
>>> sys.modules['package']
<module 'package' from 'package/__init__.py'>
>>> dir(sys.modules['package'])
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'module']
>>> sys.modules['package'].module
<module 'package.module' from 'package/module.py'>
The second paragraph you refer to talks about what names are bound by a from foo import bar
import statement. bar
is bound, foo
is not. Or, in terms of the above demonstration:
>>> module
<module 'package.module' from 'package/module.pyc'>
>>> package
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'package' is not defined
The from package import module
statement added a module
name to the namespace, but package
was not bound.