struct.pack_into()
struct.pack_into() is a Python function in the Struct Module category. Packs values into a buffer (bytearray) at the given offset. The syntax is struct.pack_into(format, buffer, offset, v1, v2, ...). Parameters: format, buffer, offset, values. Returns: None. A typical example: buf = bytearray(10)
struct.pack_into(">I", buf, 0, 42)
struct.pack_into(">H", buf, 4, 7). A close sibling is struct.pack(), which packs values into a bytes object according to a format string. A close sibling is struct.unpack(), which unpacks bytes into values according to a format string. A close sibling is struct.calcsize(), which returns the size of the struct (and bytes needed) for the given format. A close sibling is struct.unpack_from(), which unpacks bytes from a buffer starting at offset. More about this category: Binary data packing — pack, unpack, calcsize, pack_into. For a broader walkthrough, read the Struct Module guide. Related Struct Module entries: struct.pack(), struct.unpack(), struct.calcsize(), struct.unpack_from().