使用Python读取txt文档时报错

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

Traceback (most recent call last):
  File "F:/File/PythonProject/test.py", line 51, in 
    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即可

你可能感兴趣的:(python学习)