PyDocs

Nav

Binary Data Services

unpack

struct

function
  • unpack(format, buffer)
Return a tuple containing values unpacked according to the format string.

The buffer's size in bytes must be calcsize(format).  See help(struct)
for more on format strings.
1 Example
>>> record = b'raymond   \x32\x12\x08\x01\x08'
>>> name, serialnum, school, gradelevel = unpack('<10sHHb', record)

>>> from collections import namedtuple
>>> Student = namedtuple('Student', 'name serialnum school gradelevel')
>>> Student._make(unpack('<10sHHb', record))
Student(name=b'raymond   ', serialnum=4658, school=264, gradelevel=8)
from the Python docs
See Also
No see-alsos for struct/unpack
0 Notes
No notes for unpack