Python 3.2 bug? Reading the last line of a file

MRAB python at mrabarnett.plus.com
Wed May 25 17:52:39 EDT 2011


On 25/05/2011 21:54, Ian Kelly wrote:
> On Wed, May 25, 2011 at 2:00 PM, MRAB<python at mrabarnett.plus.com>  wrote:
>> You're opening the file in text mode, and seeking relative to the end
>> of the file is not allowed in text mode, presumably because the file
>> contents have to be decoded, and, in general, seeking to an arbitrary
>> position within a sequence of encoded bytes can have undefined results
>> when you attempt to decode to Unicode starting from that position.
>>
>> The strange thing is that you _are_ allowed to seek relative to the
>> start of the file.
>
> I think that with text files seek() is only really meant to be called
> with values returned from tell(), which may include the decoder state
> in its return value.

What do you mean by "may include the decoder state in its return value"?

It does make sense that the values returned from tell() won't be in the
middle of an encoded sequence of bytes.



More information about the Python-list mailing list