title: Python closure + global strangeness
body: <p>I expected this little snippet to print <em>"Why doesn't this work?"</em>  Can someone help me understand why this doesn't work as I expect?  I'm using Python 2.6, if this matters. </p>
  
  <pre><code>class WhyDoesntThisWork(object):
    def outer(self):
      acc = ''
      def inner(msg):
        global acc
        acc = acc + msg
      inner("Why doesn't")
      inner(" this work?")
      print acc
  WhyDoesntThisWork().outer()
  </code></pre>
  
  <ul>
  <li>If I include the <code>global</code> statement I get a <code>NameError: global name 'acc' is not defined
  </code>.</li>
  <li>If I don't include the <code>global</code> statement I get a <code>UnboundLocalError: local variable 'acc' referenced before assignment</code>.</li>
  </ul>