Struct module
The struct module is a Python standard-library module for converting between Python values and packed binary data using format specifications.
Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi
The Python standard-library module that converts between packed binary data and Python values using C-style format specifications.
- How it is used
- Reads and parses raw Linux joystick events for joystick-controlled robot applications.
- How deep it goes
- Works through a complete binary-reading loop, format mapping, exact-size reads, unpacking, and button-event filtering.
- Examples
- Demonstrates `/dev/input/js0`, `jstest`, the `js_event` layout, and a script reporting cross and circle button transitions.
- What you can do after
- Apply it via Python's `Struct` to decode one raw joystick event into timestamp, value, type, and number fields.
Read how Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi explains struct module →
The Quick Python Book, Fourth Edition
The struct module is a Python standard-library module for converting between Python values and packed binary representations.
- How it is used
- Handles structured binary files exchanged with C programs when ordinary text, bytes, or object persistence is insufficient.
- How deep it goes
- Explains format strings, packing, sizing, unpacking, and a record-reading loop, without detailing every format option.
- Examples
- Demonstrates an h-d-7s record containing 42, 3.14, and b'goodbye', then reads repeated fixed-size records.
- What you can do after
- Apply it via Python's struct module to pack and unpack fixed-format binary records.
Read how The Quick Python Book, Fourth Edition explains struct module →
Related concepts
- standard librarypart of · A standard library is a collection of reusable modules, types, functions, APIs, and other facilities distributed with a programming language implementation or platform.
- binary datauses · Binary data is information represented as sequences of bytes rather than character-oriented text.
- struct.unpackhas part · struct.unpack is a struct-module function that parses a packed byte sequence according to a format string and returns the resulting Python values as a tuple.
- struct.packhas part · struct.pack is a struct-module function that converts supplied Python values into a packed byte sequence according to a format string.
- Linux input subsystemuses · The Linux kernel subsystem that provides a common interface for input devices such as joysticks, keyboards, and mice.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

