This is in Python 2.7. Here's an example.
v = 1
def print_v():
v += 1
print v
print_v()
How can this be rewritten that when this module is imported, I don't get this:
$ python -c "import the_above_module"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "the_above_module.py", line 9, in <module>
print_v()
File "the_above_module.py", line 6, in print_v
v += 1
UnboundLocalError: local variable 'v' referenced before assignment