本文主要是介绍(20210129已解决)SyntaxError: Non-ASCII character ‘\xe6‘ in file filename.py , but no encoding decla,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
-
Overview
如题,运行程序出现上述提示。
-
原因解析
这个问题经常是出现在
crontab
设置运行python
时。同样的程序,在IDE中直接运行是正常的。
The reason why it works differently in console and in the IDE is, likely, because of different default encoding set. You can check it by running:L
import sys print(sys.getdefaultencoding())
The default for Python2 is
ASCII
, while Python3utf-8
. -
解决方案
Add this code for encoding at the just begin of the code source:
# -*- coding: utf-8 -*-
-
References
- SyntaxError of Non-ASCII character [duplicate]
- Why declare unicode by string in python?
这篇关于(20210129已解决)SyntaxError: Non-ASCII character ‘\xe6‘ in file filename.py , but no encoding decla的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!