Home  >  Article  >  Backend Development  >  python中文乱码的解决方法

python中文乱码的解决方法

WBOY
WBOYOriginal
2016-06-16 08:46:171678browse

乱码原因:
源码文件的编码格式为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)
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn