Python 如何在文件中每个停止字的末尾添加文本

Python 如何在文件中每个停止字的末尾添加文本,python,Python,我所做的是在文件中的每个stopwords中附加一个string=“NOTRELATED”。这是我的代码,但它不起作用: stop_words = set(stopwords.words('english')) for line in word_tokenize(input_file): if line == stop_words: line = line.strip("\n") + " NOTRELATED\n" output_file.write(l

我所做的是在文件中的每个stopwords中附加一个string=“NOTRELATED”。这是我的代码,但它不起作用:

stop_words  = set(stopwords.words('english'))
for line in word_tokenize(input_file):
    if line == stop_words:
        line = line.strip("\n") + " NOTRELATED\n"
        output_file.write(line)
标识符命名错误。你的意思是单词

if line == stop_words:

相等测试,
==
,不正确。你的意思是如果单词在stop\u words:

有什么问题吗?请编辑问题并添加错误消息以及对您尝试执行的操作的更好解释。输出文件为空表示它不工作,但如果我删除条件“if line==stop_words:”则它工作。它在文件的每一行中都添加了NOTRELATED。请编辑问题,而不是在注释中回答。我已经尝试过了,但它提取了stopwords并保留了其他行。您的注释表明,与问题中的代码不同,如果word不在stop\u words:,您的意思是
if line == stop_words: