[issue13912] ImportError using __import__ and relative level 1
Jason R. Coombs
report at bugs.python.org
Mon Jan 30 20:31:06 CET 2012
Jason R. Coombs <jaraco at jaraco.com> added the comment:
Sorry for the mistake.
I corrected the pkgB package, but the result is the same:
jaraco at devjaraco:~$ tree master
master
├── __init__.py
├── __init__.pyc
├── pkgA
│ ├── foo.py
│ ├── foo.pyc
│ ├── __init__.py
│ └── __init__.pyc
└── pkgB
├── bar.py
└── __init__.py
2 directories, 8 files
jaraco at devjaraco:~$ python2.7 -c 'import master.pkgA; print("pkgA.__package__ is {}".format(master.pkgA.__package__)); import master.pkgA.foo'
pkgA.__package__ is None
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "master/pkgA/foo.py", line 2, in <module>
bar = __import__('pkgB', level=1).bar
ImportError: No module named pkgB
As you can see, __package__ for pkgA is None. Same is true for master.__package__.
----------
resolution: invalid ->
status: closed -> open
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13912>
_______________________________________
More information about the Python-bugs-list
mailing list