【再回首Python之美】【乱码】治疗输出中文却显示乱码的杂症
2018-02-08 21:44
309 查看
一排给csdn解决方法1
脚本首行加#coding:utf-8
print u"我是中文字符串"
解决方法2
str = "我是中文字符串"
print str.decode("UTF-8")
解决方法3
将方法2定义为一个函数,以后调用使用。def decode_str(sentence):
return sentence.decode("UTF-8") print decode_str("我是中文字符串")
示例代码#coding:utf-8
#ex_decode_chinese.py
self_file = __file__ #save current file absolute path
#解决python脚本输出含有中文的字符串,而执行后却出现乱码的问题
print "\n===1st method==="
print u"你好,我治疗乱码。"
print "\n===2nd method==="
sentence = "你好,我也治疗乱码。"
print "%s" % sentence.decode("UTF-8")
print "\n===3rd method==="
def decode_str(sentence):
return sentence.decode("UTF-8")
print decode_str("你好,我也能治疗乱码。")
print "\nexit %s" % self_file
编译执行
(end)
相关文章推荐
- python调用os.system执行系统命令,中文输出显示乱码
- Python pandas plot输出图形中显示中文乱码问题
- Python matplotlib pyplot中title() xlabel() ylabel()无法显示在中文(方框乱码)的解决办法
- 【Python】遍历某目录下的所有文件夹与文件的路径、输出中文乱码问题
- MySQL客户端输出窗口显示中文乱码问题解决办法
- eclipse 编译python时控制台的中文输出时乱码
- python输出中文乱码的问题
- 关于python在cmd中输出中文乱码的问题
- python输出htmltestrunner中文乱码如何解决
- python 控制台输出中文乱码问题
- windows下python2.7输出中文乱码问题
- 关于python在cmd中输出中文乱码的问题
- Python中文全攻略 中文乱码 输出中文乱码
- python 网页显示 json序列化中文乱码
- Python 3下使用Matplotlib工具画图,中文显示乱码的问题解决(修改配置文件)
- Python爬虫起步:一步步解决中文乱码显示
- python输出htmltestrunner中文乱码如何解决
- mysql命令行中文显示乱码和输出表格不能对齐解决办法
- python中列表,字典输出中文乱码
- Python3 中记录日志并输出到 log 文件中的方法(防止输出中文乱码)