參考以下範例:
#! python2
""" Author: Martin Lee """
import struct
with open('out.bin','wb') as f:
f.write(struct.pack('B8sHHL', 22, 'Hi World', 1, 2, 0x3322))
fin =
open("out.bin", "rb")
i =
struct.unpack('B8sHHL', fin.read())
fin.close()