#!/usr/bin/python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
print "hello world 我是中文"
存储为hello.py文件 在cmd运行, 中文为乱码
资料查找:
源码文件的编码格式为utf-8,但是window的本地默认编码是gbk,所以在控制台直接打印utf-8的字符串当然是乱码了!
解决方法1:
mystr ="hello world 我是中文"
print mystr.decode('utf-8').encode('gbk')
mystr ="hello world 我是中文"
import sys
ype = sys.getfilesystemencoding()
print mystr.decode('utf-8').encode(type)