On 8 Sep 2021, at 06:39, Steven D'Aprano <steve@pearwood.info> 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') 121404708502361365413651784 bytes.from_int(121404708502361365413651784, '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' Barry