[英]unicode decode error: how to skip invalid characters
有什么方法可以预处理文本文件并跳过这些字符?
UnicodeDecodeError: 'utf8' codec can't decode byte 0xa1 in position 1395: invalid start byte
尝试这个:
str.decode('utf-8',errors='ignore')
I think your text file have some special character, so 'utf-8' can't decode. 我认为您的文本文件具有一些特殊字符,因此'utf-8'无法解码。
You need to try using 'ISO-8859-1' instead of 'utf-8'. 您需要尝试使用“ ISO-8859-1”而不是“ utf-8”。 like this:
像这样:
import sys
reload(sys).setdefaultencoding("ISO-8859-1")
# put your code here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.