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'
If that's not the API being suggested, that's going to be confusing.
How about bytes.bchr()?
bytes.bchr(n) --> a single byte
bytes.from_int(n, byteorder) --> one or more bytes
Personally, I think I would use the one or more bytes version more then
the single bchr version, so if we only had one, I vote for that.
--
Steve
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/4BZ6MTOZM23UXMIUCMHVH3QXCN2ICOJ2/
Code of Conduct: http://python.org/psf/codeofconduct/