all Python 3structfunction
struct.calcsize()
format
Returns the number of bytes a struct format occupies when packed.
Syntax
struct.calcsize(format)
The result depends on the prefix: without one (or with '@') sizes are native and padding is inserted between fields, so calcsize('ci') is 8 on a typical 64-bit machine while calcsize('<ci') is 5. No padding is added at the end: 'ic' and 'ci' give different sizes. For files and networks use '<', '>' or '!' — sizes are standard there and the same everywhere.
Examples
import struct
print(struct.calcsize('<ci')) # → 5
print(struct.calcsize('ci')) # → ? 8 на типичной 64-битной машине — выравнивание
print(struct.calcsize('!HHI')) # → 8
See also
Open in the full glossarydocs.python.orgReport an inaccuracy