[Python-3000] bytes and dicts (was: PEP 3137: Immutable Bytesand Mutable Buffer) (original) (raw)

Phillip J. Eby pje at telecommunity.com
Sat Sep 29 23:47:39 CEST 2007


At 12:04 PM 9/29/2007 -0700, Gregory P. Smith wrote:

On 9/29/07, Jeffrey Yasskin <<mailto:jyasskin at gmail.com>jyasskin at gmail.com> wrote: On 9/29/07, Phillip J. Eby <<mailto:pje at telecommunity.com>pje at telecommunity.com> wrote: > At 07:33 AM 9/29/2007 -0700, Guido van Rossum wrote: > >Until just before 3.0a1, they were unequal. We decided to raise > >TypeError because we noticed many bugs in code that was doing things > >like > > > > data = f.read(4096) > > if data == "": break > > Thought experiment: what if read() always returned strings, and to > read bytes, you had to use something like 'f.readinto(ob, 4096)', > where 'ob' is a mutable bytes instance or memory view?

Using what encoding? read() should raise an exception on a file opened as binary in that case.

Yes, that's what I meant -- the availability of read() and readinto() would be mutually exclusive.

And instead of readinto() how about readbytes() that just returns bytes and raises an exception on non-binary mode files.

Sure.

(readinto for buffers is a good idea and i think we should have it but that idea could be taken further to allow for even more scattered IO into a mutable buffer; thats another discussion and should be a PEP of its own)

Fair enough, although readbytes() can be implemented in terms of readinto(), while the reverse isn't the case.



More information about the Python-3000 mailing list