from nltk.corpus import stopwords
print "starting to read \n"
fw=open('cde.txt','w');
with open('test.txt') as fp:
for line in fp:
fw.write('\n')
fw.write(line)
fp.close()
fw.close()
print "\ndone with writing \n"
print "starting to print from another file \n"
with open('cde.txt','r+') as ss:
for line in ss:
for word in line.split():
if word in stopwords.words('english'):
#ss.write(line.remove(word))
ss.remove(word)
#print line.rstrip()
ss.close()
#for word in line.split():
print "done with printing from another file"
我运行此脚本,但不断收到AttributeError的: '文件' 对象有没有属性 '删除'
AttributeError: 'file' object has no attribute 'remove'
错误。
你究竟想实现什么? –
[相关](http://stackoverflow.com/questions/21005921/deleting-a-specific-word-from-a-file-in-python) – Idos
我想从文件中删除停用词 – sk79