pack把基本数据变成bytes
unpack把bytes解析成数据(int,char等)
import struct
name = b'muyu'
job = b'coder'
year = 2018
bytes = struct.pack('4s5si', name, job, year)
print(bytes)
# b'muyucoder\x00\x00\x00\xe2\x07\x00\x00'
content = struct.unpack('4s5si', bytes)
print(content)
# (b 'muyu', b'coder', 2018)
网友评论