How to make inner functions see variables of enclosing function?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2009402/read-write-python-closures">Read/Write Python Closures</a>  </p>
</blockquote>



<p>In the following function, the internal function does not modify the argument but just modifies the copy. </p>

<pre><code>def func():
  i = 3
  def inc(i):
    i = i + 3
  print i
  inc(i)
  inc(i)
  print i

func()
</code></pre>

<p>Is it possible to avoid repeated code and put that inside a function in python? I tried the following too but it throws error <code>UnboundLocalError: local variable 'i' referenced before assignment</code></p>

<pre><code>def func():
  i = 3
  def inc():
    i = i + 3
  print i
  inc()
  inc()
  print i

func()
</code></pre>
