Editing a file by substitution

alex23 wuwei23 at gmail.com
Tue Aug 12 04:27:59 CEST 2008


On Aug 12, 12:03 pm, Brad <bmal... at berkeley.edu> wrote:
> So let's say I want to edit this file and change Volume from 940 to 950.

Personally, I'd recommend avoiding re and sticking with the standard
string functions.

Something like this should be pretty effective:

>>> open('outfile','w').writelines(l.replace('Volume 940','Volume 950') for l in open('myfile','r'))



More information about the Python-list mailing list