The problem is very awkward, the outside definition of a variable xxx, and then in a Python function to reference this variable, and change its value, the results of the error local variable ' xxx ' referenced before assignment, the code is as follows:
xxx = def printfilename (strfilename): if xxx = = 23:print strFileName xxx = printfilename ("file")
The wrong meaning is that the variable XXX is not defined before the reference, which is not defined above. But then I took xxx = 24 after the sentence was removed, then no problem, and then think of Python in a global keyword is used to refer to the overall variables, try it, sure enough:
xxx = def printfilename (strfilename): global xxx if xxx = = 23:print strFileName xxx = printfilename ("file")
A variable that originally had the same name in the Python function as the global if you have a value that modifies a variable, it becomes a local variable, and a reference to that variable will naturally occur before you modify it, and if you decide that you want to refer to the global variable and you want to modify it, you must add the Global keyword.
[end]