#!/usr/bin/python import struct import binascii # Create Struct instance s = struct.Struct('hhl'); # Pack information packed = s.pack(1, 2, 3);#pack data into a string print s.format print s.size print binascii.hexlify(packed) # Unpack information unpacked = s.unpack(packed); print unpacked, type(unpacked);