title: Why does assigning to my global variables not work in Python?
body: <p>I'm having terrible trouble trying to understand python scoping rules.</p>
  
  <p>With the following script:</p>
  
  <pre><code>a = 7
  
  def printA():
      print "Value of a is %d" % (a)
  
  def setA(value):
      a = value
      print "Inside setA, a is now %d" %(a)
  
  
  print "Before setA"
  printA()
  setA(42)
  print "After setA"
  printA()
  </code></pre>
  
  <p>Gives the unexpected (to me) output of:</p>
  
  <pre>
      Before setA
      Value of a is 7
      Inside setA, a is now 42
      After setA
      Value of a is 7
  </pre>
  
  <p>Where I would expect the last printing of the value of a to be 42, not 7. What am I missing about Python's scope rules for the scoping of global variables?</p>