Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>+1 to @icktoofay - I would put more stock in that answer than mine, so take this one with a grain of salt as it is my admittedly inexperienced understanding of the process:</p> <p>As mentioned by others, your main issue is circular imports. Others will comment more intelligently, but the gist of what is happening is:</p> <ol> <li><code>import B</code> - this happens as soon as you run A.py`, so you then go to B.py and immediately come across import A.</li> <li>As <code>A</code> has a different name in the current namespace, it gets imported again (to verify this, add <code>print __name__</code> above <code>import B</code> in <code>A.py</code> - you'll see two different names appear).</li> <li>When <code>A</code> gets imported into <code>B</code>, it brings the <code>__global__ = 'not seen yet'</code> declaration with it, so when you say <code>self.glo = A.__global__</code>, you are getting that variable (and not the modified one because that particular code doesn't get executed in <em>this</em> version of <code>A</code>).</li> <li>Same with <code>A.Data.__var__</code> - you haven't run <code>init</code> in this module (because it isn't your 'main' <code>A</code>), so nothing has been modified yet.</li> <li>Per the above, you can see why <code>A.__global__</code> and <code>A.Data.__var__</code> will also show 'not seen yet' - they haven't been modified and are the same as the variables above.</li> <li>Your code in <code>A</code> in the <code>__main__</code> section executes as normal because it is operating on that version of the module, which does go through all of the initializations you specify.</li> </ol>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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