speed up linecache.getline()
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Oct 13 12:44:34 EDT 2009
En Tue, 13 Oct 2009 10:21:31 -0300, <bbarbero at inescporto.pt> escribió:
> I am using linecache.getline, to access to a line in a long file. It s
> really fast, appx 4seconds, but I was just wandering if any of you, know
> either another way, or there is something that I can do to speed it
> up... thank you very much for your help!!
If all the lines in the file have exactly the same length, you may seek to
the specific line and read it at once.
Otherwise I'm afraid you have to read all the previous n-1 lines to get to
line n, and that's what makes it slow.
--
Gabriel Genellina
More information about the Python-list
mailing list