I'm getting a really weird problem in my long experience with python..
In advance i want to say that i want to know WHY does this happen, and not how to change my code or how to fix it because i can do it too.
I'm using python2.7.3 and using the __future__ absolute_import
feature.
I have a little complex module structure.. I have a module q.x.y.z
. If at the top I do import q.x.a.b
it works, but if i do import q.x.a.b as _b
it fails saying that q.x doesn't have "a" (which have been imported a couple of times before this module) anyone has enough experience to know what's happening?
I'm pretty sure its not a circular import problem because I only need to remove the "as _b
" and it magically works. And also is not a naming problem because I'm really careful about that.
file structure is as follows:
q/
+ __init__.py
+ main.py #execution entry point
--- x/
+ __init__
+ a/
+ __init__
+ b.py
+ y/
+ __init__
+ z.py # import q.x.a.b
its ran from the parent folder of q pkg> python q\main.py and it contains this:
from __future__ import absolute_import
import sys, os
if __name__=='__main__':
sys.path[0] = os.getcwd()
import q
q.run()
a little related to circular imports but yet the main question is WHY does it happens when i use "as"?
the traceback goes something like this:
q/main.py: q.run()
q/x/__init__.py : from q.x import a, y, k
q/x/a/__init__.py : from q.x.a import d, e, f
q/x/a/f.py : from q.x.y import z as _z
q/x/y/__init__.py : from q.x.y import g, h, z
q/x/y/h.py : import q.x.a.d as _d
could this has something to do? https://stackoverflow.com/a/1835089/260242 or this https://stackoverflow.com/a/11309252/260242
a sample of the code, which actually fails... go to test/q/x/y/h.py and change import ... as _d to import ... and you'll see http://puu.sh/16C3j