I recently started learning Python and found that once there are Chinese comments in the code, errors will be reported
Cause
If there are non ASCII characters in the file, you need to specify the encoding Declaration on the first or second line
Solution
Add such a sentence in the first or second line
# — Coding: UTF-8–
Perfect solution
Similar Posts:
- Solutions to Python Chinese annotation errors
- [Solved] Python pip install Error: SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xc6
- SyntaxError: Non-ASCII character ‘\xe2‘ in file
- Python Error: Non-UTF-8 code starting with ‘\xe7’ [How to Solve]
- [Solved] Python Numpy Data load error: Unicode error: unpicking a python object failed: Unicode decodeerror
- UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-1:
- [Solved] SSH Remote execute Python 3 error: Unicode encodeerror: ‘ASCII’ codec
- Non-ASCII character ‘\xe8’ in file xxx.py on line 8, but no encoding declared
- [Solved] Python Error: UnicodeDecodeError: ‘gb2312’ codec can’t decode byte 0xa4 in position… : illegal multibyte sequence
- Error in reading Chinese path of pydev in eclipse