python3.6,出现'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byte怎么办
#Calthreekingdomsv1.pyimportjiebatxt=open("threekingdoms.txt","r",encoding="utf-8").r...
#Calthreekingdomsv1.py
import jieba
txt = open("threekingdoms.txt", "r", encoding="utf-8").read()
words = jieba.lcut(txt)
counts = {}
for word in words:
if len(word) == 1:
continue
else:
counts[words] = counts.get(word,0) + 1
items = list(count.items())
items.sort(key=lambda x:x[1], reverse=True)
for i in range(15):
word,count = item[i]
print("{0:<10}{1:>5])".format(word,count))
这是代码
Traceback (most recent call last):
File "D:\pathon\examples\Statisicthreekingdoms.py", line 3, in <module>
txt = open("threekingdoms.txt", "r", encoding="utf-8").read()
File "D:\pathon\lib\codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byte
这是报错 展开
import jieba
txt = open("threekingdoms.txt", "r", encoding="utf-8").read()
words = jieba.lcut(txt)
counts = {}
for word in words:
if len(word) == 1:
continue
else:
counts[words] = counts.get(word,0) + 1
items = list(count.items())
items.sort(key=lambda x:x[1], reverse=True)
for i in range(15):
word,count = item[i]
print("{0:<10}{1:>5])".format(word,count))
这是代码
Traceback (most recent call last):
File "D:\pathon\examples\Statisicthreekingdoms.py", line 3, in <module>
txt = open("threekingdoms.txt", "r", encoding="utf-8").read()
File "D:\pathon\lib\codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byte
这是报错 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询