Today, when compiling a Python program, there has been "non-ascii character ' Xe5 ' in file" error problem
1 syntaxerror:non-ascii character '\xe5' in file knn.py on line No encoding declared; See http://python.org/dev/peps/pep-0263/ for details
Why the problem occurred:
Python, by default, is encoded in ASCII, and if you include Chinese (or other non-English language) in your Python source code, even if you save your own Python source file in UTF-8 format, it still doesn't work.
The workaround is simple, just add the following code at the beginning of the file.
1 # -*-coding:utf-8-*-
Special NOTE: The above statement must be added to the first line of the source code!!!!
The default Python file is ASCII encoded, in the header add #-*-coding:utf-8-*-The specified file encoding format is utf-8, then the file you can use in Chinese or other text.
Python "non-ascii character ' Xe5 ' in file" error question (GO)