Phenomenon:
Copy a normal py file, modify part of the code, save and execute Python demo.py. An error message appears: syntax error: non-utf-8 code starting with ‘\ xe7’
reason:
The text encoding copied elsewhere may not be utf8
Solution 1:
Python 3 uses UTF-8 format by default
Generally, you don’t need to add it at the beginning # -*- coding:utf-8 -*-
However, some Chinese characters are still unrecognized and throw non-utf-8 code starting with ‘\ xe7’ If you are wrong, you need to add this sentence to the first line.
# -*- coding:utf-8 -*-
Solution 2:
Python 3 demo.py so that there will be no error prompt during execution
Solution 3:
Click the encoding UTF-8 in the lower right corner of vscode, save the current file as UTF-8, and then execute Python demo.py without error prompt.