Possible Duplicate:
Read/Write Python Closures
In the following function, the internal function does not modify the argument but just modifies the copy.
def func():
  i = 3
  def inc(i):
    i = i + 3
  print i
  inc(i)
  inc(i)
  print i
func()
Is it possible to avoid repeated code and put that inside a function in python? I tried the following too but it throws error UnboundLocalError: local variable 'i' referenced before assignment
def func():
  i = 3
  def inc():
    i = i + 3
  print i
  inc()
  inc()
  print i
func()
 
     
     
     
    