UnicodeEncodeError: 'latin-1' codec can't encode characters,python3 中文乱码

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 9-13: ordinal not in range(256)spa

后来苦思冥想找资料,最后发现一个办法,能够解决上述问题,就是:3d

在下图所示处加上下面箭头所指那句,即图后蓝色代码code

 

account = accountraw.encode("utf-8").decode("latin1")

blog

 

file="中国.xls".decode("utf-8")#将中文进行decode解码也就是将utf-8转为unicode
data=xlrd.open_workbook(file)
2.控制台输出中文乱码
解决方法:
print("中国").decode('utf-8').encode('gbk')
#源码是utf-8,控制台是默认gbk输出,
最好本身去更改一下设置就好(在file-settings-fileEncodings-utf-8)两个都选成utf-8,这样就能够直接输出
缘由:utf-8

 

主要缘由是Excel中读取数据乱码解决办法以下:unicode

相关文章
相关标签/搜索