美文网首页
UnicodeDecodeError: ‘utf-8’ code

UnicodeDecodeError: ‘utf-8’ code

作者: 啊啊啊啊啊1231 | 来源:发表于2021-04-30 01:09 被阅读0次

solution0:

open the .txt file in notepad (default in windows), then choose the encoding method as "utf8", then save the file in this format.

solution0-1:

the pickle file in different python environment will also lead to this problem. For example, if xx.pickle is saved in python2. There will arise some problems when loading the pickle file in python3 environment.

soluntion1:

file=open(path,encoding='UTF-8',errors='ignore')

solution 2:

import codecs

fr = open(‘test.txt’)

The problem can be solved by changing to the following:

fr= codecs.open(‘test.txt’, ‘r’,encoding= u’utf-8’,errors=‘ignore’)

相关文章

网友评论

      本文标题:UnicodeDecodeError: ‘utf-8’ code

      本文链接:https://www.haomeiwen.com/subject/onigrltx.html