问题描述
最初的源码:
Python中常常会遇到编码错误的问题,之前一遇到错就再gbk和utf-8之间徘徊,每一次都是靠运气来解决问题,但这次撞到了南墙,切实的思考了一番,预知如何做,敬请往下看....
解决方案:
根本问题在于不知道文档的编码方式,所以我们只需要查询文档的编码方式就ok啦,查出来编码方式之后,将encoding对应的编码方式修正即可~
贴代码:
import chardet
currentFile = open('./data/user_pay_info.csv',mode='rb')
content = currentFile.read()
print(chardet.detect(content))
import chardet
currentFile = open('./data/user_download.csv',mode='rb')
content = currentFile.read()
print(chardet.detect(content))
成功输出:
如有错误,希望朋友们可以指正🙏