Python 3.2 bug? Reading the last line of a file

Ian Kelly ian.g.kelly at gmail.com
Wed May 25 16:54:25 EDT 2011


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.



More information about the Python-list mailing list