What am I missing?
The integers between 0 and 255 map directly to a particular byte value.
But any other integer could be expressed as a wide variety of multiple byte combinations.
The proposal here covers byte-order, but what about 16 vs 32 vs 64 bits? Unsigned vs signed?
I thought that’s what the struct module is for.
There is the byte representation of Python’s bignum, but is that consistent across platforms and implementations? (Micropytjon, PyPy, IronPython, Jython)
And even if so, is it useful?
NOTE: my objection to “bchr”, whether as a builtin or not is not the functionality, it’s the name. Equating a byte with a character is a legacy of C ( and Python 2” — in Python 3, they are completely distinct concepts. Yes, that is serious bike-shedding :-)
On Wed, Sep 8, 2021 at 10:16 AM Barry Scott firstname.lastname@example.org wrote:
On 8 Sep 2021, at 06:39, Steven D'Aprano email@example.com wrote:
On Tue, Sep 07, 2021 at 08:09:33PM -0700, Barry Warsaw wrote:
I think Nick is on board with bytes.fromint() and no bchr(), and my sense of the sentiment here is that this would be an acceptable resolution for most folks. Ethan, can you reconsider?
I haven't been completely keeping up with the entire thread, so apologies if this has already been covered. I assume that the idea is that bytes.fromint should return a single byte, equivalent to chr() returning a single character.
To me, it sounds like should be the opposite of int.from_bytes.
int.from_bytes(b'Hello world', 'little')
# should return b'Hello world'
:>>> int.from_bytes(b'\x00\x00\x00\x01', byteorder='big') 1 :>>> bytes.from_int(1) would return b'\x01'? Without a length it cannot return b'\x00\x00\x00\x01'
Python-Dev mailing list -- firstname.lastname@example.org To unsubscribe send an email to email@example.com https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://firstname.lastname@example.org/message/TTFJ4VP5... Code of Conduct: http://python.org/psf/codeofconduct/