On Wed, 30 Jun 2010 10:03:49 -0700
Guido van Rossum <[email protected]> wrote:
>
> > Also, please note that values used by seek() and tell() on
> > text I/O are "opaque cookies". While they can happen to match the
> > raw binary file position, it is a mere coincidence (or an
> > implementation detail, at your will). Therefore, reusing tell() values
> > of a binary file to seek() a TextIOWrapper accessing the same file
> > is wrong.
>
> Well, um, I actually designed it carefully so that bytes offsets
> *would* work as text offsets in those cases where they make sense at
> all.
Ah, this is embarrassing. I always assumed it was an implementation
detail since neither the PEP nor the module docs say otherwise.
PEP 3116 clearly says:
“Unlike with raw I/O, the units for .seek() are not specified - some
implementations (e.g. StringIO) use characters and others (e.g.
TextIOWrapper) use bytes.”
And also:
“.seek(pos: object, whence: int = 0) -> int
Seek to position pos. If pos is non-zero, it must be a cookie
returned from .tell() and whence must be zero.”
“it must be a cookie returned from .tell()” here seems to imply that
non-zero values of other origin should not be used.
Regards
Antoine.
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com