go to specific line in text file
John Machin
sjmachin at lexicon.net
Tue Jun 17 06:58:14 EDT 2008
On Jun 17, 8:10 pm, Patrick David <patrick.da... at tu-clausthal.de>
wrote:
> Hello NG,
>
> I am searching for a way to jump to a specific line in a text file, let's
> say to line no. 9000.
> Is there any method like file.seek() which leads me to a given line instead
> of a given byte?
If by "jump" you mean without reading the preceding 8999 lines, and by
"text file" you mean variable length records without a separate index
structure, that method hasn't been implemented yet. AFAIK it hasn't
been implemented in any other language either :-)
The linecache module may be what you want, depending on how closely
your access patterns match those the module was designed for.
Cheers,
John
More information about the Python-list
mailing list