아마 내 커피는 아침에 충분히 강한 아니지만,이 문제가 지금 나를 혼란 : (. 그것이 func2()
에 a = 'bar'
을 오류를하지 제기 년대 print a
문의합니다)함수의 컨텍스트에서 전역 변수의 값을 설정하면 UnboundLocalError가 발생합니까?
>>> a = 'foo'
>>> def func1():
... print a
...
>>> def func2():
... print a
... a = 'bar'
...
>>> func1()
foo
>>> func2()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in func2
UnboundLocalError: local variable 'a' referenced before assignment
누군가 여기서 나 한테 설명 할 수 있니?
가능한 복제본 [Python 범위] (http://stackoverflow.com/questions/146359/python-scope) –