使用Python读取txt文档时报错

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/z919167107/article/details/90081341

Python读取txt文档时出现错误,报错信息为:

Traceback (most recent call last):
  File "F:/File/PythonProject/test.py", line 51, in <module>
    bio_extract()
  File "F:/File/PythonProject/test.py", line 42, in bio_extract
    jieba.load_userdict("F:\\File\\PythonProject\\myFlaskBlog\\stopwords.txt")
  File "F:\Software\python64bit\lib\site-packages\jieba\__init__.py", line 383, in load_userdict
    raise ValueError('dictionary file %s must be utf-8' % f_name)
ValueError: dictionary file F:\File\PythonProject\myFlaskBlog\stopwords.txt must be utf-8

解决方法为:

打开对应的txt文档,选择文件”->“另存为”,选择编码方式为utf-8即可

猜你喜欢

转载自blog.csdn.net/z919167107/article/details/90081341