I have something like this:
def a():
#do something
foo = 0
def b():
foo += 2
# do something
b()
#do something
a()
but it says
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
a()
File "<pyshell#5>", line 7, in a
b()
File "<pyshell#5>", line 5, in b
foo += 2
UnboundLocalError: local variable 'foo' referenced before assignment
How can I access foo without making it global?