how to write a line in a text file

en.karpachov at ospaz.ru en.karpachov at ospaz.ru
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:
> 
> http://developer.apple.com/documentation/mac/Files/Files-25.html#MARKER-9-163

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.

-- 
jk



More information about the Python-list mailing list