0
点赞
收藏
分享

微信扫一扫

UnicodeEncodeError: 'gbk' codec can't encode character: illegal multibyte sequence


又是python的编码问题了,我都想哭了,windows系统默认编码是gbk,然后你用GBK方式打开写入的txt文件,写入utf-8格式的字符,就要报错了。。。。

我的解决方案是在写入的时候加入一个utf-8编码:

with open(output_path, "w",encoding='utf-8') as file:
for word in counter_list:
file.write(word[0])
file.write("\n")
# print(word[0]) #输出字典的键
#print(word[1]) # 输出字典的值


参考文献


UnicodeEncodeError: 'gbk' codec can't encode character: illegal multibyte sequence




举报

相关推荐

0 条评论