To create one byte of a given value, you can use the chr() function:
>>> chr(5) '\x05' >>> chr(5) * 5 '\x05\x05\x05\x05\x05'
or you can use bytearray() with the correct number of integers:
>>> str(bytearray(5 * [5])) '\x05\x05\x05\x05\x05'
or use array.array() with the same:
>>> import array >>> array.array('B', 5*[5]).tostring() '\x05\x05\x05\x05\x05'
or use the struct.pack() function to pack integers in bytes:
>>> import struct >>> struct.pack('{}B'.format(5), *(5 * [5])) '\x05\x05\x05\x05\x05'
There may be more ways :-)
source share