inserting into a file

Fredrik Lundh fredrik at pythonware.com
Mon Sep 11 09:32:05 EDT 2006


"Sai Krishna M" wrote:

> One crude idea i had was to read the file in a list and insert the
> string correspondingly.

file systems usually don't support insertion and deletion, so if you want to move
things around, you have to do that yourself.

reading and writing lists (using readlines/writelines) works well, as long as the files
aren't too large.

> Is there any other way to do this?

not with plain files.  if you need to do lots of inserts/deletes, you should probably
use a database manager instead (which uses more elaborate data structures on
disk).  see e.g. the "dbm" and "bsddb" modules in the standard library.

</F> 






More information about the Python-list mailing list