import struct # unpack() parses the string to a tuple format = ‘1s2s1s1s‘ line = ‘12345‘ col = struct.unpack(format, line) print col # calcsize() returns the number of characters # in a given format string format = ‘30s30s20s1s‘ print struct.calcsize(format)
struct.unpack(format,string)按照format格式将string解压为元组。
struct.pack(format,v1,v2,...) 按照format格式将v1,v2压缩成单一字符串
struct.calcsize(format) 返回format的字符总数。