Note that there are some explanatory texts on larger screens.

plurals
  1. POPython import AS fails with absolute imports
    primarykey
    data
    text
    <p>I'm getting a really weird problem in my long experience with python..</p> <p>In advance i want to say that i want to know <strong>WHY does this happen</strong>, and not how to change my code or how to fix it because i can do it too.</p> <p>I'm using python2.7.3 and using the <code>__future__ absolute_import</code> feature. I have a little complex module structure.. I have a module <code>q.x.y.z</code>. If at the top I do <code>import q.x.a.b</code> it works, but if i do <code>import q.x.a.b as _b</code> 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 "<code>as _b</code>" and it magically works. And also is not a naming problem because I'm really careful about that.</p> <p>file structure is as follows:</p> <pre><code>q/ + __init__.py + main.py #execution entry point --- x/ + __init__ + a/ + __init__ + b.py + y/ + __init__ + z.py # import q.x.a.b </code></pre> <p>its ran from the parent folder of q pkg> python q\main.py and it contains this:</p> <pre><code>from __future__ import absolute_import import sys, os if __name__=='__main__': sys.path[0] = os.getcwd() import q q.run() </code></pre> <p>a little related to circular imports but yet the main question is <strong>WHY does it happens when i use "as"?</strong></p> <p>the traceback goes something like this:</p> <pre><code>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 </code></pre> <p>could this has something to do? <a href="https://stackoverflow.com/a/1835089/260242">https://stackoverflow.com/a/1835089/260242</a> or this <a href="https://stackoverflow.com/a/11309252/260242">https://stackoverflow.com/a/11309252/260242</a></p> <p>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 <a href="http://puu.sh/16C3j" rel="nofollow noreferrer">http://puu.sh/16C3j</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload