confusing behavior with python import
<p><p>Hi, there.</p>

<p>I have two files:</p>

<p><i>a.py:</i></p>

<pre><code>print('in a')
import b

print('var')
VAR = 1

def p():
    print('{}, {}'.format(VAR, id(VAR)))

if __name__ == '__main__':
    VAR = -1
    p()
    b.p() # Where does this VAR come from?
</code></pre>

<p><i>b.py:</i></p>

<pre><code>print('in b')
import a

def p():
    a.p()
</code></pre>

<p><p>I don't understand why there're two different VARs, which is supposed to the same.</p>

<p>If I move the 'main' block to another file, everything works well, i.e, there is only one VAR.</p>

<p><i>c.py:</i></p>

<pre><code>import a
import b

if __name__ == '__main__':
    a.VAR = -1
    a.p()
    b.p()
</code></pre>

<p><p>So my question is:
<p>Why do the last two lines of a.py print different results?
<br>Don't they print the same VAR variable in a.py?
<p>BTW, I'm using python 2.7 on win7.</p>

<p>Thanks.</p>
