[Python-ideas] duck typing for io write methods

Amaury Forgeot d'Arc amauryfa at gmail.com
Fri Jun 14 08:14:31 CEST 2013


2013/6/14 Nick Coghlan <ncoghlan at gmail.com>

> On 14 June 2013 10:08, Steven D'Aprano <steve at pearwood.info> wrote:
> > The actual behaviour, where bytes(4) => b'\x00\x00\x00\x00', I consider
> to
> > be neither obvious nor especially useful. If bytes were mutable, then
> > bytes(4) would be a useful way to initialise a block of four bytes for
> later
> > modification. But they aren't, so I don't really see the point. The
> obvious
> > way to get four NUL bytes is surely b'\0'*4, so it's also redundant.
>
> My (vague) recollection is that the intended use case was for
> bytearray (i.e. exactly the "initialize a section of memory for
> subsequent modification" use case you mention), and the bytes
> constructor just supports it for consistency reasons.


In early 3.0, bytes were mutable. So I guess this bytes(4) behavior was
just forgotten.


-- 
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130614/bad15873/attachment.html>


More information about the Python-ideas mailing list