[issue13912] ImportError using __import__ and relative level 1

2012-11-10 Thread Jason R. Coombs
Jason R. Coombs added the comment: Yes. Since Nick's comment , I've been using importlib for all programmatic imports with great success. -- resolution: -> invalid status: pending -> closed ___ Python tracker ___

[issue13912] ImportError using __import__ and relative level 1

2012-11-09 Thread Eric Snow
Eric Snow added the comment: Are you okay on this, Jason? -- status: open -> pending ___ Python tracker ___ ___ Python-bugs-list maili

[issue13912] ImportError using __import__ and relative level 1

2012-01-31 Thread Brett Cannon
Brett Cannon added the comment: On Mon, Jan 30, 2012 at 18:33, Eric Snow wrote: > > Eric Snow added the comment: > > Jason: just a warning. importlib_backport is a relatively naive tool for > generating the backport from the py3k source. It's also relatively fragile > and at this point prob

[issue13912] ImportError using __import__ and relative level 1

2012-01-31 Thread Nick Coghlan
Nick Coghlan added the comment: It sounds like you may want runpy.run_module [1], rather than using imports at all. If you know how many levels up you want to go, it isn't hard to do your own munging of __name__ to create absolute module references to pass to runpy. The signature of __import_

[issue13912] ImportError using __import__ and relative level 1

2012-01-30 Thread Eric Snow
Eric Snow added the comment: The problem is your level is off and the name is incomplete. master.pkgA.foo.py should have the following: __import__('pkgB.bar', master.pkgA.__dict__, level=2).bar or __import__('pkgB.bar', master.pkgA.__dict__, fromlist=['-'], level=2) -- __

[issue13912] ImportError using __import__ and relative level 1

2012-01-30 Thread Eric Snow
Eric Snow added the comment: Jason: just a warning. importlib_backport is a relatively naive tool for generating the backport from the py3k source. It's also relatively fragile and at this point probably doesn't work with the default branch. -- _

[issue13912] ImportError using __import__ and relative level 1

2012-01-30 Thread Jason R. Coombs
Jason R. Coombs added the comment: Thanks for the tip Brent. Still, no luck. jaraco@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):

[issue13912] ImportError using __import__ and relative level 1

2012-01-30 Thread Brett Cannon
Brett Cannon added the comment: I see your mistake now: you need to call it as __import__('pkgB', globals(), index=1), else __import__ has no clue how to anchor your import in the relative package space. Try that and let me know if it makes it work. And why exactly are you trying to call __i

[issue13912] ImportError using __import__ and relative level 1

2012-01-30 Thread Jason R. Coombs
Jason R. Coombs added the comment: Sorry for the mistake. I corrected the pkgB package, but the result is the same: jaraco@devjaraco:~$ tree master master ├── __init__.py ├── __init__.pyc ├── pkgA │   ├── foo.py │   ├── foo.pyc │   ├── __init__.py │   └── __

[issue13912] ImportError using __import__ and relative level 1

2012-01-30 Thread Brett Cannon
Brett Cannon added the comment: You have a typo in a filename: it should be pkgB/__init__.py (not the missing trailing underscores). -- nosy: +brett.cannon resolution: -> invalid status: open -> closed ___ Python tracker

[issue13912] ImportError using __import__ and relative level 1

2012-01-30 Thread Eric Snow
Eric Snow added the comment: what value do you see for __package__ in pkgA? -- nosy: +eric.snow ___ Python tracker ___ ___ Python-bug

[issue13912] ImportError using __import__ and relative level 1

2012-01-30 Thread Jason R. Coombs
New submission from Jason R. Coombs : 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