[Python-ideas] duck typing for io write methods

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Fri Jun 14 11:16:23 CEST 2013


Wolfgang Maier <wolfgang.maier at ...> writes:

> 
> Steven D'Aprano <steve <at> ...> writes:
> 
> > b'\x00\x04'
> > b'\x04\x00'
> > b'\x00\x00\x00\x04'
> > b'\x04\x00\x00\x00'
> > b'\x00\x00\x00\x00\x00\x00\x00\x04'
> > b'\x04\x00\x00\x00\x00\x00\x00\x00'
> >
> 
> these would be ways to make bytes([seq of ints]) work with numbers > 255,
> which is currently not possible. Maybe bytes([seq of ints]) could take an
> additional encoding argument that specifies how many bytes to reserve per int.
>

Chris Rebert just pointed out the new Python 3.2 int methods .to_bytes and
.from_bytes, which do exactly this. Does anybody know, why .from_bytes was
implemented as an int method instead of a bytes method .to_int ??
Wolfgang




More information about the Python-ideas mailing list