Files, Seek, and Readlines. A newbie question

Aahz aahz at pythoncraft.com
Mon Apr 1 11:07:18 EST 2002


In article <Ts%p8.149254$ZR2.64157 at rwcrnsc52.ops.asp.att.net>,
John Purser <NO_SPAM_jmpurser2 at attbi.com> wrote:
>
>I'm using a large (>120,000 lines) sorted ASCII text file as an index.  I
>started running into problems as soon as I began to use the .seek() to
>position before a read.  Even when not opened as a binary file seek moves by
>bytes not lines.  Is there a line oriented seek version?  Is there a better
>way to get to line 50 than:
>myFile.seek(0)
>myFile.readlines(49)
>Record = myFile.readline()

Not unless each line has a fixed length.  Better yet, use a database.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Why is this newsgroup different from all other newsgroups?



More information about the Python-list mailing list