[Python-ideas] Direct byte<->int conversions (was Re: bitwise operations on bytes)
greg.ewing at canterbury.ac.nz
Tue Aug 11 03:05:26 CEST 2009
Nick Coghlan wrote:
> One slight quirk of the C API that probably shouldn't be replicated is a
> size of 0 translating to an integer result of zero. For the Python API,
> passing in an empty byte sequence should trigger a ValueError.
Why? This seems like a perfectly logical limiting case
> int.from_bytes(data, *, little_endian=None, signed=True)
> little_endian would become a three-valued parameter for the Python
> version: None = native; False = little-endian; True = big-endian.
I don't like the idea of a three-valued boolean. I also
don't like boolean parameters whose sense is abritrary
(why is it called "little_endian" and not "big_endian",
and how do I remember which convention was chosen?)
My suggestion would be to use the same characters that
the struct module uses to represent endianness (">"
for big-endian, "<" for little-endian, etc.)
More information about the Python-ideas