On 9/9/2021 1:56 PM, Ethan Furman wrote:
On 9/9/21 9:37 AM, Barry Warsaw wrote:
> While I think int.to_bytes() is pretty obscure (I knew about it,
forgot about it, and learned
> about it again!) I’m not so sure it’s any less obscure than a
proposed bytes.fromint().
>
> So why don’t we just relax int.to_bytes()’s signature to include
natural default values:
>
> int.to_bytes(length=1, byteorder=sys.byteorder, *, signed=False)
Default arg values are one of Python's great features.
> Then I ought to be able to just do
>
> >>> (65).to_bytes()
> b’A’
That seems so much worse than
>>> bchr(65)
b'A'
;-)
Except that .to_bytes already exists, and arguably should have had such
defaults from the beginning, making any new function to do the same
thing superfluous.
--
Terry Jan Reedy
_______________________________________________
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/A7OQPRVVE4WPQ7YCIMCGK2AMPXR6GYTB/
Code of Conduct: http://python.org/psf/codeofconduct/