Today, when compiling a python program, there is a "non-ascii character ' Xe5 ' in file" error problem
Syntaxerror:non-ascii character ' \xe5 ' in file knn.py on line, but no encoding declared; Http://python.org/dev/peps/pep-0263/for Details
The cause of the problem occurs:
Python is encoded by default in ASCII, and if you include Chinese (or some other non-English language) in your own Python source code, even if you save your own Python sources in UTF-8 format, this is still not a good practice.
The solution is simple, just add the following code at the beginning of the file.
#-*-Coding:utf-8-*-
Special NOTE: The above statement must be added to the first line of the source code ....
The default Python file is encoded in ASCII, with the #-*-Coding:utf-8-*-in the header to specify that the file's encoding format is utf-8, so you can use Chinese or other text in the file.