I have a text file that I need to loop through in search of various strings. When I find these strings, I want to overwrite the lines with new text.
I get the impression the fileinput module is good for this, but I can't find an example of how to do it.. I'm thinking it would start along the lines of :
import fileinput
import string
for line in fileinput.input('c:\test.txt'):
rc = string.find(line,"some text"
if rc > -1:
line = "replacement text"
Only I'm not sure how to write out the next lines to the file because I never really opened a file (did I?).
Any suggestions?
Thanks
I get the impression the fileinput module is good for this, but I can't find an example of how to do it.. I'm thinking it would start along the lines of :
import fileinput
import string
for line in fileinput.input('c:\test.txt'):
rc = string.find(line,"some text"
if rc > -1:
line = "replacement text"
Only I'm not sure how to write out the next lines to the file because I never really opened a file (did I?).
Any suggestions?
Thanks