On 2021-09-09 00:29, Rob Cliffe via Python-Dev wrote:


On 08/09/2021 21:21, Christopher Barker wrote:

[snip]
NOTE: my objection to “bchr”, whether as a builtin or not is not the functionality, it’s the name.

[snip]
Why not byte() ?

I happened to need to convert an integer to a byte recently and I settled on
      bytes((i,))
I don't know if I missed a more elegant solution (suggestions welcome),
but if I could write
      byte(i)
that would feel more Pythonic to me.

Well, I tend to see a byte as a value like an int.

If you slice a bytestring, you'd expect to get a bytestring, and you do.

If you subscript a bytestring, you expect to get a byte. You get an int, and that suggests that a byte is an int. (In Python 2 you got a bytestring, in Python 3 you get an int.)

The name could be misleading as byte(i) would return a bytestring, not a byte/int.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/UU2QW6KV36H5RRFL6UG2REOFRWWXKCUK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to