On this page
struct.error
Prev: struct.calcsize | Up: struct | Next: struct.iter_unpack
Rel: struct.calcsize, struct.iter_unpack, struct.pack, struct.pack_into
Ref: docs.python.org โ struct.error
Tags: #public #python3 #stdlib #struct
Import
import struct
from struct import error
Signature & Overview
struct.error(...)
struct.error class.
Methods & Attributes
error.add_note(self, note, /)โ Add a note to the exceptionerror.with_traceback(self, tb, /)โ Set self.traceback to tb and return self.
Usage
import struct
try:
struct.unpack("!I", b"\x01\x02")
except struct.error as exc:
assert "4 bytes" in str(exc)
Gotchas
- Raised on buffer-length mismatches, invalid format strings, or integer overflow (e.g., packing
70000into"!H").
REPL Inspect
from struct import error
help(error)
Linked from
- tuts/python3/stdlib_module/struct
- tuts/python3/stdlib_module/struct/calcsize
- tuts/python3/stdlib_module/struct/iter_unpack
- 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/iter_unpack 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