I have a two nested python functions, which look like this:
def outer():
t = 0
def inner():
t += 1
print(t)
inner()
Trying to call outer
results in the following error:
>>> outer()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "sally.py", line 6, in outer
inner()
File "sally.py", line 4, in inner
t += 1
UnboundLocalError: local variable 't' referenced before assignment
I thought adding the line global t
before t += 1
would help, except it didn't.
Why is this happening? How do I get around this problem, other than passing t to inner
everytime I call it?