In Python, why do I get an 'undefined local variable' error for counters but not for lists?
<p>If I alter a variable declared at the top of the file/module from within a method (no classes involved), it only works in the case of lists/containers, but not if my variable was a simple counter. See the following code for example:</p>

<pre><code>counter = 0
counterList = []

def incrementCounter():
    counter += 1

def addToList():
    counterList.append(1)

# works:
addToList()

# doesn't work:
incrementCounter()    

print counterList, counter
</code></pre>

<p>What is the reason for this differing behaviour?</p>
