title: Can not increment global variable from function in python
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them">Using global variables in a function other than the one that created them</a>  </p>
  </blockquote>
  
  
  
  <p>I have the following script:</p>
  
  <pre><code>COUNT = 0
  
  def increment():
      COUNT = COUNT+1
  
  increment()
  
  print COUNT
  </code></pre>
  
  <p>I just want to increment global variable COUNT, but this gives me the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 6, in &lt;module&gt;
      increment()
    File "test.py", line 4, in increment
      COUNT = COUNT+1
  UnboundLocalError: local variable 'COUNT' referenced before assignment
  </code></pre>
  
  <p>Why is it so?</p>