Python error: Syntaxerror:non-ascii character ' \xe5 ' workaround

Source: Internet
Author: User

Recently Learning machine learning, the above code are some Python code, for Python is just some basic things, just met a low problem, but still record it.

In the Python code there is a Chinese, but I put the #-*-Coding:utf-8-*-This sentence to the third line, so led to appear, such as the following error:

' \xe5 '

1. The solution is as simple as putting the encoded sentence on the first line:

# -*-coding:utf-8-*- # !/usr/bin/python # Filename:tree.py

2. But if the first line is about the Python interpreter, you can also put the encoded phrase on the second line:

# !/usr/bin/python # -*-coding:utf-8-*- # Filename:tree.py

3. Of course, the code of the sentence can also be written in the following style:

# Coding=utf-8

Resources

"1" http://my.oschina.net/panjavay/blog/142682

"2" https://www.python.org/dev/peps/pep-0263/

Python error: Syntaxerror:non-ascii character ' \xe5 ' workaround

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.