python中文乱码的解决方法
2017-08-08 18:58
302 查看
乱码原因:
源码文件的编码格式为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)
源码文件的编码格式为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操作mysql中文显示乱码的解决方法
- python sqlobject(mysql)中文乱码解决方法
- Python BeautifulSoup中文乱码问题的2种解决方法
- Python2.x中文乱码问题解决方法
- Python BeautifulSoup中文乱码问题的2种解决方法
- python中文乱码的解决方法
- python 中文乱码解决方法
- python 采集中文乱码问题的完美解决方法
- Python 3下Matplotlib画图中文显示乱码的解决方法
- Python BeautifulSoup中文乱码问题的2种解决方法
- Python的raw_input语句包含中文,在Windows环境CMD中显示乱码的解决方法
- python sqlobject(mysql)中文乱码解决方法
- python抓取中文网页乱码通用解决方法
- Python的raw_input语句包含中文,在Windows环境CMD中显示乱码的解决方法
- python中文乱码的解决方法
- Python Email应用的中文乱码问题解决方法
- python 写csv文件,excel打开中文乱码解决方法
- python下中文乱码的解决方法
- python解决Fedora解压zip时中文乱码的方法
- python操作mysql中文显示乱码的解决方法