On this page
struct.iter_unpack
Prev: struct.error | Up: struct | Next: struct.pack
Rel: struct.calcsize, struct.error, struct.pack, struct.pack_into
Ref: docs.python.org — struct.iter_unpack
Tags: #public #python3 #stdlib #struct
Import
import struct
from struct import iter_unpack
Signature & Overview
struct.iter_unpack(format, buffer, /)
Return an iterator yielding tuples unpacked from the given bytes.
Usage
import struct
buf = struct.pack("!HHHH", 1, 2, 3, 4)
pairs = list(struct.iter_unpack("!HH", buf))
assert pairs == [(1, 2), (3, 4)]
Gotchas
- Buffer size must be an exact multiple of
calcsize(fmt): Raisesstruct.errorif trailing bytes remain.
REPL Inspect
from struct import iter_unpack
help(iter_unpack)
Linked from
- tuts/python3/stdlib_module/struct
- tuts/python3/stdlib_module/struct/calcsize
- tuts/python3/stdlib_module/struct/error
- tuts/python3/stdlib_module/struct/pack
- tuts/python3/stdlib_module/struct/pack_into
- tuts/python3/stdlib_module/struct/Struct
- tuts/python3/stdlib_module/struct/unpack
- tuts/python3/stdlib_module/struct/unpack_from
Related notes
- tuts/python3/stdlib_module/struct/calcsize Linked here; links to this page; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/error Linked here; links to this page; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/pack Linked here; links to this page; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/pack_into Linked here; links to this page; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/Struct Linked here; links to this page; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/unpack links to this page; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/unpack_from links to this page; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib