randomly write to a file

rohit rohitsethidce at gmail.com
Mon May 7 18:41:08 EDT 2007


hi gabriel,
i am utilizing file names and their paths which are written to a file
on a singe line.
now if i use records that would be wasting too much space as there is
no limit on the no. of characters (at max) in the path.
next best approach i can think of is reading the file in memory
editing it and writing the portion that has just been altered and the
followiing lines
but is there a better approach you can highlight?

> You can only replace a line in-place with another of exactly the same
> length. If the lengths differ, you have to write the modified line and all
> the following ones.
> If all your lines are of fixed length, you have a "record". To read record
> N (counting from 0):
>    a_file.seek(N*record_length)
>    return a_file.read(record_length)
> And then you are reinventing ISAM.
>
> --
> Gabriel Genellina





More information about the Python-list mailing list