This is a somewhat strange question. I need to convert an integer id, such as 123456, to a byte in the format b'123456'. I'm not doing an actual conversion to bytes however, I'm just changing the format to look like a byte and be interpreted as one. So I literally need to do the following:
10 = b'10'
20 = b'20'
30 = b'30'
bytes([10]) == b'\n'
b'10'
Convert the int
to a str
then .encode
into bytes
:
>>> x = 123456
>>> bs = str(x).encode('ascii')
>>> bs
b'123456'