How do I take words from one text file out of another? Python -
tran = open("rep-small.txt") stop = open("stopsql.txt") ctran = open("cleantran.txt.","w") badlist = [] line in stop: badlist.append(line) def cleantxt(): line in tran: word in badlist: line = line.replace(word,"") ctran.write(line)
it writing ctran.txt isn't taking out words stop. stop file formatted way:
a
and
the
it
with each word on different line.
you can skip loop: (btw calling function cleantxt()?)
tran = open("rep-small.txt") ctran = open("cleantran.txt.","w") def cleantxt(): line in tran.readlines(): word in badlist: line = line.replace(word,"") ctran.write(line) ctran.close() open("stopsql.txt") stop: # with-statement calls close() function after finished executing badlist = stop.readlines() # add lines list cleantxt()
Comments
Post a Comment