randomly write to a file

kyosohma at gmail.com kyosohma at gmail.com
Mon May 7 16:38:11 EDT 2007


On May 7, 2: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

Hi,

Looking through the archives, it looks like some recommend reading the
file into a list and doing it that way. And if they file is too big,
than use a database. See links below:

http://mail.python.org/pipermail/tutor/2006-March/045571.html
http://mail.python.org/pipermail/tutor/2006-March/045572.html

I also found this interesting idea that explains what would be needed
to accomplish this task:

http://mail.python.org/pipermail/python-list/2001-April/076890.html

Have fun!

Mike




More information about the Python-list mailing list