The most common reason for this error is that you’re using multiple global declarations in the same function. Consider this example:
x = 0
def func(a, b, c):
if a == b:
global x
x = 10
elif b == c:
global x
x = 20
If you run this in a recent version of Python, the compiler will issue a SyntaxWarning pointing to the beginning of the func function.
Here’s the right way to write this:
x = 0
def func(a, b, c):
global x # <- here
if a == b:
x = 10
elif b == c:
x = 20
Similar Posts:
- How to Solve Tensorflow SincNet Error
- Python Visual C++ 9.0 is required [Two Method to Solve]
- Python uses decorator and reports error typeerror: ‘nonetype’ object is not callable ‘
- Cannot find bounds of current function
- The solution of Python extension problem “unable to find vcvarsall. Bat”
- PyTorch :TypeError: exceptions must derive from BaseException
- [Solved] Lexical declaration cannot appear in a single-statement context
- [Solved] Vue Upgrade Error: TypeError:Cannot read property ‘parseComponent’ of undefined
- error: ‘to_string’ was not declared in this scope
- Solution to fatal error in launcher: unable to create process using ‘”‘In PIP installation