使用stopwords时出现NameError: name 'stopwords' is not defined错误求助
解决nltk中
stopwords未定义的错误 你遇到的NameError是因为只下载了stopwords语料,但没有从nltk的corpus模块中导入stopwords对象,Python找不到未导入的名称,所以报错。
修正后的代码如下:
import nltk from nltk.corpus import stopwords # 新增导入语句 import re nltk.download('stopwords') print(stopwords.words('english'))
添加from nltk.corpus import stopwords后,就能正常调用stopwords.words('english')获取英文停用词列表了。
内容的提问来源于stack exchange,提问作者Sebastian Galindo
相关产品推荐
相关产品推荐

