how to write a line in a text file

en.karpachov at en.karpachov at
Tue Jul 26 06:53:33 CEST 2005

Tue, Jul 26, 2005 at 01:41:36PM +1000, Steven D'Aprano пишет:
> Long ago, when dinosaurs roamed the Earth, (a.k.a. 
> "before OS X on the Macintosh") Apple suggested a bit 
> of Pascal code for safely updating a file:

That snippet doesn't write data to the existing file. It writes data into
the new tempfile and then renames it, as well as the FileInput object does.
> Most of the code is Macintosh-specific, but the 
> principle is not: when over-writing a file, make sure 
> that the user can recover from any error up to and 
> including power failure without losing the data on disk.

Well, it's what (R)DBMS are for, but plain files are not.


More information about the Python-list mailing list