UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xb4 in position 6: illegal multibyte sequence
错误原因是因为解码错误,用gbk去解码unicode当然不行,所以我们在读取文本需要加入参数’r’,或者转为utf-8格式
解决方法:(两者都可)
with open('words.txt','r',encoding='UTF-8') as f:
text = f.read()
UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xb4 in position 6: illegal multibyte sequence
错误原因是因为解码错误,用gbk去解码unicode当然不行,所以我们在读取文本需要加入参数’r’,或者转为utf-8格式
解决方法:(两者都可)
with open('words.txt','r',encoding='UTF-8') as f:
text = f.read()