From: Gregory Brown Date: 2009-05-03T03:57:45+09:00 Subject: Re: Read and re-write file with one open? On Sat, May 2, 2009 at 4:05 AM, 7stud -- wrote: > So let's ask that question about the solution you've decided to adopt. > Suppose your program is at the point where it has written half of the > altered data back to the file, and the file contains half altered data > and half original data.  Then your program crashes.  What are you left > with? > > The "rewriting a file" issue has been hashed out by many programmers for > decades.  You can either try to come up with your own screwy method, or > you can adopt an accepted idiom.  Within the accepted idiom, modules > like Tempfile were created to deal with the problem of overwriting an > existing file name, and it provides a shortcut. Thanks for going into the detail here. I threw the atomic save solution out there, but didn't give much background, and this establishes a much better motivation for it. -greg