Today in the net copy of a piece of code, the code is very simple, every line looks like the indentation of the indentation, run the time appeared the following error:
[solution]
1. The most common reason for this error is that, indeed, there is no indentation. Depending on the number of lines of error, the code looks fine, there are indenting, and there are no syntax errors.
2. After looking through the code and realizing that nothing really went wrong, it occurred to me to display all the characters in the current Python script (including Spaces and TAB characters) to see if there was any indentation or any other special characters.
Notepad++, the current text editor, has a setting to display all characters.
in:
view — > Display symbol – & GT; Show Spaces and tabs
so you can see whether or not our Python code is indented.
Finally, it turns out that the error is actually caused by the fact that the error line appears to be indented, but actually it is not. This is the root of the problem.
I found a problem that none of the Python code I copied was indent, which requires extra attention when We copy other people’s code. Don’t make it look like your code is indented to feel ok, it’s not actually indented.
Read More:
- Python problem: indenta tionError:expected an Error resolution of indented block
- Python error prompt unindent does not match any outer indentation level
- Solve the problem of unable to locate package python3.6 when upgrading from python3.5 to python3.6 in ubantu16.04
- Python – [encoding] in Python os.system Solution to Chinese garbled code when calling CMD command
- The python version output from the command line is inconsistent with the python version in the current CONDA environment
- Can’t find Python executable “D:\python3\python.exe”, you can set the PYTHON env variable.
- The problem of “value error: zero length field name in format” in Python 2.6.6 of CentOS 6.9
- Pychar reported an error. Unable to set the python SDK in Python 3.8. This SDK appears to be invalid.
- Solve the problem of Python in Windows environment: Fatal error in launcher: Unable to create process using’”‘ in pip installation
- Run Python file for the first time with eclipse / pydev: “UTF-8 ‘codec can’t decode byte 0xc4 in position
- In Python, import XXX does not report an error, but in IPython (Jupiter notebook)
- Implementation of screen cleaning in Python idle
- Install in Python 3. X web.py
- From in Python__ future__ The role of import *
- Translate() and maketrans() methods of string in Python
- Python 3.4 compiler prompt error: unexpected indent
- Coding and decoding Base64 in Python
- Error reported in Python: syntax error: invalid character in identifier
- Run with Python console solution is set by default for all projects in pcharm
- How to solve oserror: [errno 98] address already in use and kill the python3 process