liveBook · Manning

Struct module

The struct module is a Python standard-library module for converting between Python values and packed binary data using format specifications.

How 2 Manning books explain it

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

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.