On Wed, Sep 08, 2021 at 05:06:08PM -0000, Brandt Bucher wrote: > Steven D'Aprano wrote: > > 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. > > I'm a bit lost here... why are we convinced at all that we need a new > way to do this? Hasn't this functionality already existed for years? > > >>> x = int.from_bytes(b"*", "little") > >>> x > 42 > >>> x.to_bytes(1, "little") > b'*'
TIL :-) How have I never noticed to_bytes until now? o_O -- Steve _______________________________________________ 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/QLYAHWFN5V27RKIJWTGFNYLG7KQJMJ6Q/ Code of Conduct: http://python.org/psf/codeofconduct/