{
    "mode": "pydoc",
    "parameter": "_struct",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/_struct/json",
    "generated": "2026-06-02T14:15:23Z",
    "sections": {
        "NAME": {
            "content": "struct\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Functions to convert between Python values and C structs.\nPython bytes objects are used to hold the data representing the C struct\nand also as format strings (explained below) to describe the layout of data\nin the C struct.\n\nThe optional first format char indicates byte order, size and alignment:\n@: native order, size & alignment (default)\n=: native order, std. size & alignment\n<: little-endian, std. size & alignment\n>: big-endian, std. size & alignment\n!: same as >\n\nThe remaining chars indicate types of args and must match exactly;\nthese can be preceded by a decimal repeat count:\nx: pad byte (no data); c:char; b:signed byte; B:unsigned byte;\n?: Bool (requires C99; if not available, char is used instead)\nh:short; H:unsigned short; i:int; I:unsigned int;\nl:long; L:unsigned long; f:float; d:double; e:half-float.\nSpecial cases (preceding decimal count indicates length):\ns:string (array of char); p: pascal string (with count byte).\nSpecial cases (only available in native format):\nn:ssizet; N:sizet;\nP:an integer type that is wide enough to hold a pointer.\nSpecial case (not in native mode unless 'long long' in platform C):\nq:long long; Q:unsigned long long\nWhitespace between formats is ignored.\n\nThe variable struct.error is an exception raised on errors.\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "builtins.Exception(builtins.BaseException)\nstruct.error\nbuiltins.object\nStruct\n",
            "subsections": [
                {
                    "name": "class Struct",
                    "content": "|  Struct(fmt) --> compiled struct object\n|\n|  Methods defined here:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  sizeof(...)\n|      S.sizeof() -> size of S in memory, in bytes\n|\n|  iterunpack(self, buffer, /)\n|      Return an iterator yielding tuples.\n|\n|      Tuples are unpacked from the given bytes source, like a repeated\n|      invocation of unpackfrom().\n|\n|      Requires that the bytes length be a multiple of the struct size.\n|\n|  pack(...)\n|      S.pack(v1, v2, ...) -> bytes\n|\n|      Return a bytes object containing values v1, v2, ... packed according\n|      to the format string S.format.  See help(struct) for more on format\n|      strings.\n|\n|  packinto(...)\n|      S.packinto(buffer, offset, v1, v2, ...)\n|\n|      Pack the values v1, v2, ... according to the format string S.format\n|      and write the packed bytes into the writable buffer buf starting at\n|      offset.  Note that the offset is a required argument.  See\n|      help(struct) for more on format strings.\n|\n|  unpack(self, buffer, /)\n|      Return a tuple containing unpacked values.\n|\n|      Unpack according to the format string Struct.format. The buffer's size\n|      in bytes must be Struct.size.\n|\n|      See help(struct) for more on format strings.\n|\n|  unpackfrom(self, /, buffer, offset=0)\n|      Return a tuple containing unpacked values.\n|\n|      Values are unpacked according to the format string Struct.format.\n|\n|      The buffer's size in bytes, starting at position offset, must be\n|      at least Struct.size.\n|\n|      See help(struct) for more on format strings.\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  format\n|      struct format string\n|\n|  size\n|      struct size in bytes\n"
                },
                {
                    "name": "class error",
                    "content": "|  Method resolution order:\n|      error\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors defined here:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.Exception:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "calcsize",
                    "content": "Return size in bytes of the struct described by the format string.\n"
                },
                {
                    "name": "iter_unpack",
                    "content": "Return an iterator yielding tuples unpacked from the given bytes.\n\nThe bytes are unpacked according to the format string, like\na repeated invocation of unpackfrom().\n\nRequires that the bytes length be a multiple of the format struct size.\n"
                },
                {
                    "name": "pack",
                    "content": "pack(format, v1, v2, ...) -> bytes\n\nReturn a bytes object containing the values v1, v2, ... packed according\nto the format string.  See help(struct) for more on format strings.\n"
                },
                {
                    "name": "pack_into",
                    "content": "packinto(format, buffer, offset, v1, v2, ...)\n\nPack the values v1, v2, ... according to the format string and write\nthe packed bytes into the writable buffer buf starting at offset.  Note\nthat the offset is a required argument.  See help(struct) for more\non format strings.\n"
                },
                {
                    "name": "unpack",
                    "content": "Return a tuple containing values unpacked according to the format string.\n\nThe buffer's size in bytes must be calcsize(format).\n\nSee help(struct) for more on format strings.\n"
                },
                {
                    "name": "unpack_from",
                    "content": "Return a tuple containing values unpacked according to the format string.\n\nThe buffer's size, minus offset, must be at least calcsize(format).\n\nSee help(struct) for more on format strings.\n"
                }
            ]
        },
        "FILE": {
            "content": "(built-in)\n\n",
            "subsections": []
        }
    },
    "summary": "struct",
    "flags": [],
    "examples": [],
    "see_also": []
}