So I'm having a very strange error right now. I found where it happens, and here's the simplest code that can reproduce it.
def cause_an_error():
some_var = False
def some_nested_func():
print some_var
#some_var = True
some_nested_func()
>>> cause_an_error()
False
If you run it as-is, it prints "False". But if you uncomment that line, it gives an error:
Traceback (most recent call last):
File "<pyshell#224>", line 1, in <module>
cause_an_error()
File "<pyshell#223>", line 6, in cause_an_error
some_nested_func()
File "<pyshell#223>", line 4, in some_nested_func
print some_var
UnboundLocalError: local variable 'some_var' referenced before assignment
Notice the error occurs on the line that worked just fine before.
Any ideas what causes this and how I can fix this? I'm using Python 2.6.1.