出现了错误UnicodeDecodeError

输入代码

img


img

代码里有encoding='utf-8',为社么还是会显示UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 71: illegal multibyte sequence

img

stopword = [line.strip() for line in open(filepath, 'r').readlines()]

这一行的open()中加 encoding='utf-8' 参数, 改成

stopword = [line.strip() for line in open(filepath, 'r', encoding='utf-8').readlines()]

img

如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

img

你的stopwordlist读取文件没有设置编码格式

用记事本打开代码中的txt文档,另存时选取编码格式为‘utf-8',再运行代码试试。

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632