struct
can be used to read or write binary data. import struct nums = [ 0x61626364, # abcd in hex 10, 1, 256, 65536 ] with open('/tmp/struct.out', 'wb') as f: f.write(struct.pack( 'i' * len(nums), *nums))
$ od -t d4z --width=4 /tmp/struct.out 0000000 1633837924 >dcba< 0000004 10 >....< 0000010 1 >....< 0000014 256 >....< 0000020 65536 >....< 0000024