Tutorial by Examples

from struct import pack print(pack('I3c', 123, b'a', b'b', b'c')) # b'{\x00\x00\x00abc'
from struct import unpack print(unpack('I3c', b'{\x00\x00\x00abc')) # (123, b'a', b'b', b'c')
The module "struct" provides facility to pack python objects as contiguous chunk of bytes or dissemble a chunk of bytes to python structures. The pack function takes a format string and one or more arguments, and returns a binary string. This looks very much like you are formatting a stri...

Page 1 of 1