[Python-ideas] duck typing for io write methods
Nick Coghlan
ncoghlan at gmail.com
Fri Jun 14 07:44:14 CEST 2013
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.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list