[issue992389] attribute error after non-from import

Nick Coghlan report at bugs.python.org
Wed Apr 1 12:38:25 CEST 2009


Nick Coghlan <ncoghlan at gmail.com> added the comment:

No argument from me that my suggestion is a mere glimmering of an idea,
rather than a fully worked out definitely viable solution.

It was just an angle of attack I hadn't seen suggested before, so I
figured it was worth mentioning - the fact that a module is allowed to
exist in sys.modules while only half constructed is the reason "import
a.b.c" can work while "from a.b import c" or an explicit relative import
will fail - the first approach gets a hit in sys.modules and succeeds,
while the latter two approaches fail because the a.b package doesn't
have a 'c' attribute yet.

Figuring out a way to set the attribute in the parent package and then
roll it back later if the import fails is still likely to be the more
robust approach.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue992389>
_______________________________________


More information about the Python-bugs-list mailing list