Hi, there.<br><br>I have two files:<br><br>a.py:<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote"><div style="text-align: left;"># -*- coding: utf-8 -*-<br>
print('in a')<br>import b<br><br>print('var')<br>VAR = 1<br><br>def p():<br>    print('{}, {}'.format(VAR, id(VAR)))<br><br>if __name__ == '__main__':<br>    VAR = -1<br>    p()<br>    b.p() # Where does this VAR come from?<br>
</div></blockquote><div><br>b.py:<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote"># -*- coding: utf-8 -*-<br>print('in b')<br>import a<br>
<br>def p():<br>    a.p()<br></blockquote><div><br>I don't understand why there're two different VARs, which is supposed to the same.<br>Is it a bug?<br>If I move the 'main' block to another file, everything works well.<br>
<br>c.py:<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote"># coding=UTF-8<br>import a<br>import b<br><br>if __name__ == '__main__':<br>
    a.VAR = -1<br>    a.p()<br>    b.p()<br></blockquote><br></div></div>