报错:SyntaxError: Non-ASCII character '\xe4' in file

SyntaxError: Non-ASCII character '\xe1' in file recommendation.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

原因:注释里面出现了中文,而 Python 支持的 ASCII 码无中文。

在ython官网得到如下帮助信息:

Python will default to ASCII as standard encoding if no other encoding hints are given.

翻译:如果没有其他编码提示,Python将默认为ASCII作为标准编码。

To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file

翻译:要定义源代码编码,必须在源文件中第一行或第二行放置一个魔术注释。

解决办法:

在头文件中添加如下代码:

# -*- coding: utf-8 -*-

猜你喜欢

转载自www.cnblogs.com/zzdbullet/p/10163429.html