Flatfile update?

Roman Suzi rnd at onego.ru
Sun Sep 16 14:36:16 CEST 2001

On Sun, 16 Sep 2001, pwgk wrote:

>I am trying to find out if it is possible to open a flat (ascii) file for
>update in python, so I can change it's contents directly, without having
>to copy the entire contents.

It depends on the format of flat file. If you have fixed length lines,
you can change text file inplace using positioning by seek() method.
(But open file as binary for that, if your platfrom distinguishes
text/binary file modes).

>Is this possible, and if yes, does anyone know how?
>Or do I have to start digging into MySQL for that?

It depends on what you want to achieve. If your application has 1-2-3
flatfile dbs and there is no relational db readily running, flat files are
fine. (I could dare to say, they are much more secure than say MySQL.)

However, if you envision that your system will grow, you are better off
with RDBMS as soon in the development, as possible, or you will end with
numerous flat files scattered accross your system.

If you want simultaneous write access, consider locking file (or record
of file) you are accessing. (look at the fcntl module)


Sincerely yours, Roman Suzi
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Sunday, September 16, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Phobia: what's left after drinking 2 out of a 6 pack" _/

More information about the Python-list mailing list