Re: Safely modify a file in place -- am I doing it right?

2011-06-30 Thread Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote: > I have a script running under Python 2.5 that needs to modify files in > place. I want to do this with some level of assurance that I won't lose > data. E.g. this is not safe: > [snip] Thanks to all who replied, your comments were helpful. -- Stev

Re: Safely modify a file in place -- am I doing it right?

2011-06-29 Thread Chris Torek
In article <4e0b6383$0$29996$c3e8da3$54964...@news.astraweb.com> wrote: >I have a script running under Python 2.5 that needs to modify files in >place. I want to do this with some level of assurance that I won't lose >data. ... I have come up with this approach: [create temp file in suitable dir

Re: Safely modify a file in place -- am I doing it right?

2011-06-29 Thread Grant Edwards
On 2011-06-29, steve+comp.lang.pyt...@pearwood.info wrote: > I have a script running under Python 2.5 that needs to modify files in > place. I want to do this with some level of assurance that I won't lose > data. E.g. this is not safe: > > def unsafe_modify(filename): > fp = open(filename, '

Safely modify a file in place -- am I doing it right?

2011-06-29 Thread steve+comp . lang . python
I have a script running under Python 2.5 that needs to modify files in place. I want to do this with some level of assurance that I won't lose data. E.g. this is not safe: def unsafe_modify(filename): fp = open(filename, 'r') data = modify(fp.read()) fp.close() fp = open(filename,

Re: modify a file

2007-11-04 Thread Marc 'BlackJack' Rintsch
On Mon, 05 Nov 2007 01:55:50 +1100, tech user wrote: > I have a file which is large about 3.5G. > I need to modify some lines in it,but I don't like to create another file > for the result. > How can i do it? thanks. In general not a good idea unless the modification does not change the length of

modify a file

2007-11-04 Thread tech user
Hello, I have a file which is large about 3.5G. I need to modify some lines in it,but I don't like to create another file for the result. How can i do it? thanks. National Bingo Night. Play along for the chance to win $10,000 every week. Download your gamecard now at Yahoo!7 TV. http

Re: How to modify a file 'in place' ?

2005-07-22 Thread Chris Connett
There is a module in the library called fileinput, should do what you're looking for. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to modify a file 'in place' ?

2005-07-22 Thread John Machin
Elby wrote: > I'm looking for a the most simple and generic way to modify a file, with the > possibility of making backups. In fact, I would like to emulate Perl's -i > option. > > here is a bit of code, to explain it further : > > < code >

How to modify a file 'in place' ?

2005-07-22 Thread Elby
I'm looking for a the most simple and generic way to modify a file, with the possibility of making backups. In fact, I would like to emulate Perl's -i option. here is a bit of code, to explain it further : < code > from os import rename class Modif_File: def __init_