struct

  • conversions between Python values and C structs represented as Python bytes objects
In [ ]:
import struct

p = struct.pack('hhl', 1, 2, 3) # short, short, long
print(p)

print(struct.calcsize('hhl')) # 16

u = struct.unpack('hhl', p)
In [ ]:
s = struct.Struct('hhl')
p = s.pack(1, 2, 3)

u = s.unpack(p) # (1, 2, 3)