python and UnboundLocalError
<p>I have a little problem with local variables and python (2.7).</p>

<p>I have a little code :</p>

<pre><code>def foo(a):
    def bar():
        print a
    return bar()

&gt;&gt;&gt;foo(5)
5
</code></pre>

<p>Well, it's working, but if want to modify a , like this :</p>

<pre><code>def foo(a):
    def bar():
        a -= 1
    return bar()
&gt;&gt;&gt;foo(5) 
UnboundLocalError: local variable 'a' referenced before assignment
</code></pre>

<p>So I must affect 'a' to another variable.</p>

<p>But I don't understand this comportment.
Is it because when there is an assignment, python looks in the locals() variables and doesn't find it ?</p>

<p>Thanks.</p>
