First, meaning:
The local variable XXX reference was not defined before.
ii. Causes of Errors
Is that Python does not have a variable declaration, so it finds the scope of the variable by a simple rule: if there is a variable assignment inside a function, the variable is considered local, so if the value of the modified variable becomes a local variable.
Iii. The scene that produced this error
Python code:
val=9
def test (flag):
If flag:
val = 1
Else
print ' Fuck '
Return
Val
Test (0)
Error tip: unboundlocalerror:local variable '
Val' Referenced before assignment
Workaround:Using the Global keyword to illustrate that the variable is a global variable
Python code:
val=9
def test (flag):
Global Val
If flag:
val = 1
Else
print ' Test '
Return Val
Test (0) Reference: http://www.uplook.cn/biancheng/107/1078875/reprinted from: http://blog.csdn.net/joeblackzqq/article/details/35278665
Python's unboundlocalerror:local variable ' xxx ' referenced before assignment