int.to_bytes() for a single byte

Terry Reedy tjreedy at udel.edu
Tue Nov 6 22:18:44 EST 2018


On 11/6/2018 9:30 PM, jladasky at itu.edu wrote:

> b = i.to_bytes(1, "big")
> 
>Is there another function which provides a more logical interface to this straightforward task?

Yes
 >>> 33 .to_bytes(1, 'big')
b'!'
 >>> bytes((33,))
b'!'

See >>> bytes(   # in IDLE or >>> help(bytes)


-- 
Terry Jan Reedy




More information about the Python-list mailing list