I have python function that needs to set a global variable on it's first run and modify it on other runs I've tried implementing this as follows:
def foo():
if 'some_var' in globals():
some_var = some_var + 1
else:
global some_var
some_var = 0
However, I get a syntax error:
SyntaxError: name 'some_var' is used prior to global declaration
Why is this? How do I implement this functionality correctly?