New submission from Jason R. Coombs <[email protected]>:
The Python 2.7.2 docs say this about __import__:
Positive values for level indicate the number of parent directories to
search relative to the directory of the module calling __import__().
But I find that even when setting level=1, the parent directory is not searched.
I've created this project tree to replicate the issue:
jaraco@devjaraco:~$ tree master
master
├── __init__.py
├── pkgA
│ ├── foo.py
│ └── __init__.py
└── pkgB
├── bar.py
└── __init.py
2 directories, 5 files
jaraco@devjaraco:~$ cat master/pkgA/foo.py
bar = __import__('pkgB', level=1).bar
jaraco@devjaraco:~$ cat master/pkgB/bar.py
var = "success"
It fails as so with python 2.7.2:
jaraco@devjaraco:~$ python2.7 -c "import master.pkgA.foo"
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
It's conceivable I'm not using this correctly, but if so, I'm unable to find my
mistake. I've confirmed that foo.__name__ is 'master.pkgA.foo'. I've tried
using level=2 (in case I was off by one, but that wasn't the case).
----------
components: Interpreter Core
messages: 152331
nosy: jason.coombs
priority: normal
severity: normal
status: open
title: ImportError using __import__ and relative level 1
versions: Python 2.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue13912>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com