그래서 지금 당장 이상한 오류가 발생합니다. 나는 그것이 일어나는 곳을 발견했고, 그것을 재현 할 수있는 가장 간단한 코드가있다.변수에 _assigning_ 할 때 파이썬 범위 문제가 발생했습니다.
def cause_an_error():
some_var = False
def some_nested_func():
print some_var
#some_var = True
some_nested_func()
>>> cause_an_error()
False
"그대로"실행하면 "거짓"이 인쇄됩니다. 당신이 행의 주석을 해제한다면, 그것은 오류가 있습니다 : 오류가 가 전에 잘 작동 라인에서 발생
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
알 수 있습니다.
어떤 아이디어가 원인이고 어떻게 해결할 수 있습니까? Python 2.6.1을 사용하고 있습니다.
://stackoverflow.com/questions/2516652/scoping-problem-in-recursive-closure –