Python出现SyntaxError: Non-ASCII character 'xe7' in file 错误的解决办法

发现是因为Python在默认状态下不支持源文件中的编码所致。解决方案有如下三种:

一、在文件头部添加如下注释码:

 # coding=<encoding name> 例如,可添加# coding=utf-8

二、在文件头部添加如下两行注释码:

#!/usr/bin/python

# -*- coding: <encoding name> -*- 例如,可添加# -*- coding: utf-8 -*-

三、在文件头部添加如下两行注释码:

 #!/usr/bin/python

# vim: set fileencoding=<encoding name> : 例如,可添加# vim: set fileencoding=utf-8 :

原文地址:https://www.cnblogs.com/litaiqing/p/4547108.html