[Tutor] Writing to text files

Andreas Kostyrka andreas at kostyrka.org
Mon Aug 22 10:01:02 CEST 2005

Am Montag, den 22.08.2005, 09:30 +0200 schrieb Johan Geldenhuys:
> Hi all,
> I want to write to a text file with a timestamp, but I want to newest
> entry at the top. So I want to insert the next entry to the file at
> the beginning.
> I can create and append to a file and then the latest entry is at the
> bottom.
> Any ideas how this is done please?
Well, difficult. Depending upon your needs, you can either copy the
whole file, adding the timestamp at the the top, and rename it
afterwards. Expensive to do. Or if you have to add more timestamps, you
need to store it in some other "data structure", and export a log file
on demand.

Other "data structure" might be a SQL database, a directory full of
small entry files, or one file with a reversed flow.

Basically files (in most OS environments) can only be appended to.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20050822/433d8175/attachment.pgp

More information about the Tutor mailing list