Python "non-ascii character ' Xe5 ' in file" error question (GO)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.