how to read the last line of a huge file???

Ian Kelly ian.g.kelly at gmail.com
Fri Mar 4 19:54:15 EST 2011


On Fri, Mar 4, 2011 at 5:26 PM, MRAB <python at mrabarnett.plus.com> wrote:
>> UnsupportedOperation: can't do non-zero end-relative seeks
>>
>> But offset is initialized to -10. Does anyone have any thoughts on
>> what the error might be caused by?
>>
> I think it's because the file has been opened in text mode, so there's
> the encoding to consider. It may be that it's to stop you from
> accidentally seeking into the middle of a multibyte sequence, but
> there's nothing to stop you doing that when seeking relative to the
> start, for example, so it's possibly a pointless restriction.

I expect that's correct.  The doc string from Python 2 included this nugget:

    If the file is opened in text mode, only offsets returned by
tell() are legal.
    Use of other offsets causes undefined behavior.



More information about the Python-list mailing list