On this page
  1. struct.pack_into
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

struct.pack_into

Prev: struct.pack | Up: struct | Next: struct.Struct
Rel: struct.calcsize, struct.error, struct.iter_unpack, struct.pack
Ref: docs.python.org — struct.pack_into
Tags: #public #python3 #stdlib #struct


Import

import struct
from struct import pack_into

Signature & Overview

struct.pack_into(format, buffer, offset, v1, v2, ...)

Pack the values v1, v2, ... according to the format string and write the packed bytes into the writable buffer buf starting at offset. Note that the offset is a required argument. A negative offset counts from

Usage

import struct

buf = bytearray(8)
struct.pack_into("!II", buf, 0, 10, 20)
assert struct.unpack_from("!II", buf, 0) == (10, 20)

Gotchas

REPL Inspect

from struct import pack_into
help(pack_into)

Linked from

Related notes