热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_47331502
Leo泓病毒
4 年前
trueweixin_47331502

CSDN App 扫码分享
分享
评论
1
打赏
  • 复制链接
  • 举报
下一条:
源代码是这样的: import jieba txt = open("threekingdoms.txt", "r").read().decode('UTF-8') words = jieba.lcut(txt) counts = {} for word in words: if len(word) == 1: continue else: counts[word] = counts.get(word,0) + 1 items = list(counts.items()) items.sort(key=lambda x:x[1], reverse=True) for i in range(15): word, count = items[i] print ("{0:<10}{1:>5}".format(word, count)) 运行出现错误:Traceback (most recent call last): File "D:\编程\python\代码\实例10中文词频统计1.py", line 3, in <module> txt = open("threekingdoms.txt", "r").read().decode('UTF-8') UnicodeDecodeError: 'gbk' codec can't decode byte 0xb1 in position 5: illegal multibyte sequence 要读取的是中文文本,不知道为什么会出错,求大佬解获!谢谢!
立即登录