title: Why can't I change another modules variable in python?
body: <p>I'm trying to allow a second module to modify the variables of the first in a circular import, but it doesn't seem to work.</p>
  
  <p>I have 2 questions: 1) Why doesn't this work / what is the reasoning for this from a language development perspective and 2) are there any easy solutions that allow me to do the same thing perhaps in a slightly different way?</p>
  
  <p>a.py:</p>
  
  <pre><code>import b
  
  test1 = 'a'
  test2 = None
  test3 = '3'
  
  if __name__ == '__main__':
    print test1, test2, test3 #prints 'a', None, 3
    b.changeVars()
    print test1, test2, test3 #prints 'a', None, 3 (i.e. nothing has changed)
  </code></pre>
  
  <p>b.py:</p>
  
  <pre><code>import a
  
  def changeVars():
    print a.test1, a.test2, a.test3 #prints 'a', None, 3
    a.test1 = 'NEW VAR 1'
    a.test2 = 'NEW VAR 2'
    a.test3 = 'NEW VAR 3'
  
    print a.test1, a.test2, a.test3 #prints 'NEW VAR 1', 'NEW VAR 2', 'NEW VAR 3'
  </code></pre>