Re: Editing a file by substitution

2008-08-12 Thread Terry Reedy
Brad wrote: alex23 wrote: 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! If, if you have to change the file repeatedly, make it a template (either % or the ne

Re: Editing a file by substitution

2008-08-11 Thread Brad
alex23 wrote: On Aug 12, 12:03 pm, Brad <[EMAIL PROTECTED]> 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','

Re: Editing a file by substitution

2008-08-11 Thread alex23
On Aug 12, 12:03 pm, Brad <[EMAIL PROTECTED]> 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').writeline

Editing a file by substitution

2008-08-11 Thread Brad
Hi, what I'd like to do is edit an input file for a calculation with Python. Let's say that I have an input file like the following -->> BLAH BLAH BLAH Other inputs, Volume 940 m^3, maybe some more stuff STUFF STUFF -->> So let's say I