[Python-3000] On PEP 3116: new I/O base classes
Guido van Rossum
guido at python.org
Fri Jun 22 07:43:37 CEST 2007
On 6/21/07, Daniel Stutzbach <daniel at stutzbachenterprises.com> wrote:
> On 6/21/07, Guido van Rossum <guido at python.org> wrote:
> > In my mind, seek() and tell() should work like getpos() and setpos()
> > in modern C stdio -- tell() returns a "cookie" whose only use is that
> > you can later pass it to seek() and it will reset the position in the
> > sequence of code units to where it was when tell() was called. For
> > many encodings, in practice, seek() and tell() can just use byte
> > positions since the boundaries between code points always fall on byte
> > boundaries (but not the other way around). For other encodings, the
> > implementation currently in io.py encodes the incremental codec state
> > in the (very) high bits of the cookie (this is convenient since we
> > have arbitrary precision integers).
>
> If the cookie is meant to be opaque to the caller, is there a reason
> that the cookie must be an integer?
Yes, so the API for seek() and tell() can be the same for binary and
text files. It also makes it easier to persist cookies.
> Specifying the return type as opaque might also reduce the temptation
> to do perform arithmetic on them, which will work for some codecs
> (ASCII), but break later in odd ways for others.
I actually like the "open kimono" approach where users can work around
the system if they really need to.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list