On this page
struct.unpack_from
Prev: struct.unpack | Up: struct
Rel: struct.calcsize, struct.error, struct.iter_unpack, struct.pack
Ref: docs.python.org — struct.unpack_from
Tags: #public #python3 #stdlib #struct
Import
import struct
from struct import unpack_from
Signature & Overview
struct.unpack_from(format, /, buffer, offset=0)
Return a tuple containing values unpacked according to the format string.
Usage
import struct
packet = b"HDR" + struct.pack("!H", 8080) + b"TAIL"
(port,) = struct.unpack_from("!H", packet, offset=3)
assert port == 8080
Gotchas
- Reads at
offsetwithout slicing/copyingbytes: Allows trailing data after the unpacked fields, unlikestruct.unpack().
REPL Inspect
from struct import unpack_from
help(unpack_from)
Linked from
Related notes
- tuts/python3/stdlib_module/struct/unpack Linked here; links to this page; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/calcsize Linked here; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/error Linked here; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/iter_unpack Linked here; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/pack Linked here; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct/Struct Linked here; shared tags: #stdlib, #struct
- tuts/python3/stdlib_module/struct links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/struct/pack_into shared tags: #stdlib, #struct
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib