Hi tutors

 

If I need to clean a textfile (perhaps after web scraping), I have used this
method - without problems - but I'm sure there must be smarter and better
ways. 

I'm especially interested to know how I do more than just one search-replace
without having to repeat the whole step below.

 

I'm using Python 2.6.6 on a windows pc.

 

fin = open("dirtyfile.txt")

fout = open("cleanfile.txt", "w")

for line in fin:

    fout.write(line.replace('## ', '#')) 

fin.close()

fout.close()

 

Thanks,

Tommy

 

 

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to