乱码原因:
源码文件的编码格式为utf-8,但是window的本地默认编码是gbk,所以在控制台直接打印utf-8的字符串当然是乱码了!
解决方法:
1、print mystr.decode(\’utf-8\’).encode(\’gbk\’)
2、比较通用的方法:
复制代码 代码如下:
import sys
type = sys.getfilesystemencoding()
print mystr.decode(\’utf-8\’).encode(type)
上一篇:python条件和循环的使用方法