4.3.1 Struct Objects

##
4.3.1 Struct Objects

The `struct` module also defines the following type:

class `Struct`( | format)

  Return a new Struct object which writes and reads binary data according to the format string format. Creating a Struct object once and calling its methods is more efficient than calling the `struct` functions with the same format since the format string only needs to be compiled once.

  New in version 2.5.

Compiled Struct objects support the following methods and attributes:

`pack`( | v1, v2, ...)

  Identical to the `pack()` function, using the compiled format. (`len(result)` will equal `self.size`.)

`pack_into`( | buffer, offset, v1, v2, ...)

  Identical to the `pack_into()` function, using the compiled format.

`unpack`( | string)

  Identical to the `unpack()` function, using the compiled format. (`len(string)` must equal `self.size`).

`unpack_from`( | buffer[,offset `= 0`])

  Identical to the `unpack_from()` function, using the compiled format. (`len(buffer[offset:])` must be at least `self.size`).

`format`
  The format string used to construct this Struct object.