import struct p = struct.pack('hhl', 1, 2, 3) # short, short, long print(p) print(struct.calcsize('hhl')) # 16 u = struct.unpack('hhl', p)
s = struct.Struct('hhl') p = s.pack(1, 2, 3) u = s.unpack(p) # (1, 2, 3)