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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -