python closures

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
>>> def f1(init) :
... def f2() :
... init = init+1
... print init
... return f2
...
>>> f = f1(10)
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in f2
UnboundLocalError: local variable 'init' referenced before assignment