How to change outer function local variables from an inner function in Python?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13985671/modify-the-function-variables-frominner-function-in-python">Modify the function variables frominner function in python</a>  </p>
</blockquote>



<p>Say I have this python code</p>

<pre><code>def f():
    x=2
    def y():
        x+=3
    y()
</code></pre>

<p>this raises:</p>

<pre><code>UnboundLocalError: local variable 'x' referenced before assignment
</code></pre>

<p>So, how do I "modify" <code>local variable 'x'</code> from the inner function? Defining x as a global in the inner function also raised an error.</p>
