homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jaraco
Recipients jaraco
Date 2012年01月30日.17:00:47
SpamBayes Score 1.7087332e-11
Marked as misclassified No
Message-id <1327942847.95.0.649353892202.issue13912@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2012年01月30日 17:00:48jaracosetrecipients: + jaraco
2012年01月30日 17:00:47jaracosetmessageid: <1327942847.95.0.649353892202.issue13912@psf.upfronthosting.co.za>
2012年01月30日 17:00:47jaracolinkissue13912 messages
2012年01月30日 17:00:47jaracocreate

AltStyle によって変換されたページ (->オリジナル) /