On this page
struct.calcsize
Up: struct | Next: struct.error
Rel: struct.error, struct.iter_unpack, struct.pack, struct.pack_into
Ref: docs.python.org — struct.calcsize
Tags: #public #python3 #stdlib #struct
Import
import struct
from struct import calcsize
Signature & Overview
struct.calcsize(format, /)
Return size in bytes of the struct described by the format string.
Usage
import struct
assert struct.calcsize("!IHH") == 8
Gotchas
- Always specify an endianness prefix (
<,>,!,=): Without a prefix,@inserts platform-dependent C struct alignment padding.
REPL Inspect
from struct import calcsize
help(calcsize)
Linked from
- tuts/python3/stdlib_module/struct
- tuts/python3/stdlib_module/struct/error
- 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/error 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