Python出现UnicodeDecodeError: 'gbk' codec can't decode byte 0xbb in position 8: illegal multibyte sequence错误
原因是在读取文件时由于编码方式不同无法进行转换
出错代码:
for line in open('keji.txt', 'r').readlines(): print(line) corpus.append(line.strip()) # print corpus time.sleep(5)
解决方法,在打开文件语句中加入编码方式,将其改为UTF-8
for line in open('keji.txt', 'r',encoding='UTF-8').readlines(): print(line) corpus.append(line.strip()) # print corpus time.sleep(5)