Editing a file by substitution
Brad
bmalone at berkeley.edu
Mon Aug 11 23:27:09 EDT 2008
alex23 wrote:
> 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'))
Ahh yes, perhaps string function are simpler to use in this case.
Thanks Alex!
More information about the Python-list
mailing list