I have the following code:
>>> def f(v=1):
... def ff():
... print v
... v = 2
... ff()
...
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in f
File "<stdin>", line 3, in ff
UnboundLocalError: local variable 'v' referenced before assignment
I do understand why this message occurs (Python variable scope question), but how can I work with v
variable in this case? global v
doesn't work in this case.