Suppose we have a number whose exact size is unknown :
>>> import random >>> a = random.randint(2**100, 2**1000) You need to convert it to a byte array, for example:
>>> n = 258 >>> b = n.get_bytes(...) b'\x01\x02' >>> n = 749520 >>> b = n.get_bytes(...) b'\x0b\x6f\xd0' I tried to use bytes ([...]), to_bytes (...), struct.pack (...), but, as I understood in all the options, you need to specify the size of the array.
Is there anything that automatically determines the length of a number in bytes and generates a byte array?