Non-ASCII character ‘\xe5‘ in file kf1.py on line 4, but no encoding declared; see http://python.or

PYTHON运行中出现的问题:

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

Non-ASCII character ‘\xe5‘ in file kf1.py on line 4, but no encoding declared; see http://python.or

出现的原因:发现是因为Python在默认状态下不支持源文件中的编码所致

解决办法:在文件头部添加如**释码:

# coding=utf-8

 

还可以添加如下:

 #!/usr/bin/python

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