Jason R. Coombs <jar...@jaraco.com> 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):
      File "<string>", line 1, in <module>
      File "master/pkgA/foo.py", line 2, in <module>
        bar = __import__('pkgB', globals(), level=1).bar
    ImportError: No module named pkgB

I considered importlib, but it is only included for Python 2.7+ and I have to 
support Python 2.6. I'm using programmatic imports for a few  reasons:

1) I'm importing the modules for the side effects, so I don't need or want the 
name in the namespace.
2) If I import it naturally, I get pyflakes warnings that it's an used imports.
3) The order of imports is important. If I place it too early in the imports, 
it doesn't have the state it needs and fails.
4) By placing it in the top of the file with other imports, it's not obvious 
why it's being imported, so requires comments.
5) The most appropriate place to invoke this functionality is in a specific 
function, "run_app".

I see now that there is an importlib backport in the cheeseshop for earlier 
versions of Python. Given your recommendation, I'll give that a try.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13912>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to