change a string in text file then write it
Carel Fellinger
cfelling at iae.nl
Mon Nov 6 12:10:49 EST 2000
More information about the Python-list mailing list
Mon Nov 6 12:10:49 EST 2000
- Previous message (by thread): change a string in text file then write it
- Next message (by thread): change a string in text file then write it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Alex Martelli <aleaxit at yahoo.com> wrote: ... > for line in fileinput.input("thefile.txt", inplace=1): > if re.search(myre, line): > line = string.replace(line,'foo','bar') > print line Ah, this must be one of Alex favorite typos, omitting a trailing ',' :) You see, the last line should actually read: print line, #note the trailing "," the lines you get from "fileinput.input('thefile.txt', inplace=1)" have a trailing end-of-line symbol embedded if it was there in the input file. The print statement adds a trailing end-of-line symbol regardless of whether the string to write ended with one, *unless* you end the print statement with a comma, then this adding is omitted. -- groetjes, carel
- Previous message (by thread): change a string in text file then write it
- Next message (by thread): change a string in text file then write it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list