转自:http://blog.sina.com.cn/s/blog_8f27abe50100z5l6.html
SyntaxError: Non-ASCII character ‘\xe5′ in file
1 |
import os |
2 |
|
3 |
if os.name = = "nt" : |
4 |
command = "dir" |
5 |
else : |
6 |
command = "ls-l" |
7 |
|
8 |
os.system(command) |
错误信息:SyntaxError: Non-ASCII character ‘\xe5′ in fileos-system.py
解决方法:
python的默认编码文件是用的ASCII码,你将文件存成了UTF-8,解决办法很简单,在文件开头加入
# -*- coding: UTF-8-*-