UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xa8 in position

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容