UnicodeDecodeError: ‘utf-8’ code

2021-04-30  本文已影响0人  啊啊啊啊啊1231

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’)

上一篇 下一篇

猜你喜欢

热点阅读