randomly write to a file

Nick Vatamaniuc vatamane at gmail.com
Mon May 7 17:41:02 EDT 2007


Rohit,

Consider using an SQLite database. It comes with Python 2.5 and
higher.  SQLite will do a nice job keeping track of the index. You can
easily find the line you need with a SQL query and your can write to
it as well. When you have a file and you write to one line of the
file, all of the rest of the lines will have to be shifted to
accommodate, the potentially larger new line.

-Nick Vatamaniuc


On May 7, 3:51 pm, rohit <rohitsethi... at gmail.com> wrote:
> hi,
> i am developing a desktop search.For the index of the files i have
> developed an algorithm with which
>  i should be able to read and write to a line if i know its line
> number.
> i can read a specified line by using the module linecache
> but i am struck as to how to implement writing to the n(th) line in a
> file EFFICIENTLY
> which means i don't want to traverse the file sequentially to reach
> the n(th) line
>
> Please help.
> Regards
> Rohit





More information about the Python-list mailing list