readlines problems - Newbie

Chris Liechti cliechti at gmx.net
Mon Apr 1 15:04:58 EST 2002


"John Purser" <NO_SPAM_jmpurser2 at attbi.com> wrote in
news:k_1q8.146744$Yv2.44641 at rwcrnsc54: 
> I've got a little function:
> def FindLine(Record):
>      im1_Dif.seek(0)
>      im1_Dif.readlines(Record - 1)
>      test = im1_Dif.readline()
>      print test
> 
> When I call it I wind up with the same record in "test" whether I pass
> it 1 or 10.  The readlines line reads a huge chunk of text with no
> regard for lines at all.  I have no idea what is causing this.  Where
> can I find the documentation on the file methods?  I can't find them
> in the documentation. Can anyone tell me what's going on here?

in the docs:
http://www.python.org/doc/current/lib/bltin-file-objects.html

you can see that this is a limit in bytes if even implemented.

you can read all the lines in a buffer:
>>> all = im1_Dif.readlines()
and just work with the last one
>>> test = all[-1]

chris
-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list