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