Message152331
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). |
|
Date |
User |
Action |
Args |
2012-01-30 17:00:48 | jaraco | set | recipients:
+ jaraco |
2012-01-30 17:00:47 | jaraco | set | messageid: <1327942847.95.0.649353892202.issue13912@psf.upfronthosting.co.za> |
2012-01-30 17:00:47 | jaraco | link | issue13912 messages |
2012-01-30 17:00:47 | jaraco | create | |
|