About 7,580,000 results
Open links in new tab
  1. struct - C-like structures in Python - Stack Overflow

    Aug 30, 2008 · cstruct2py is a pure python library for generate python classes from C code and use them to pack and unpack data. The library can parse C headres (structs, unions, enums, and arrays …

  2. python - How to pack and unpack using ctypes (Structure <-> str ...

    If I use struct to define a binary structure, the struct has 2 symmetrical methods for serialization and deserialization (pack and unpack) but it seems ctypes doesn't have a straightforward way to do this.

  3. python - Reading a binary file into a struct - Stack Overflow

    The idiomatic way to do this in Python is use the struct module and call struct.unpack() in a loop—either a fixed number of times if you know the number of them in advance, or until end-of-file is …

  4. binary - Python struct.pack and unpack - Stack Overflow

    Oct 14, 2020 · 15 struct.pack takes non-byte values (e.g. integers, strings, etc.) and converts them to bytes. And conversely, struct.unpack takes bytes and converts them to their 'higher-order' …

  5. reading struct in python from created struct in c - Stack Overflow

    Jun 22, 2013 · I am opening the file using Python to read the file. One of the things I need to read are a struct that was created in the C function and printed in binary. In my Python code I am at the …

  6. python - convert bytes or bytearray to struct - Stack Overflow

    May 16, 2023 · 3 Two ways: one using ctypes and one using struct: For ctypes, I simplified the structure but it has the same layout for 32-bit signed integers and an unsigned byte. It works with nested …

  7. packing and unpacking variable length array/string using the struct ...

    The struct module does only support fixed-length structures. For variable-length strings, your options are either: Dynamically construct your format string (a str will have to be converted to a bytes before …

  8. python - How to switch byte order of binary data - Stack Overflow

    Dec 13, 2012 · struct.error: bad char in struct format How can I unpack these values with the correct byte ordering? Am I stuck reading in the two bytes separately then reassembling them in the python …

  9. Python-bytes () vs struct.pack () - Stack Overflow

    They do two different things; compare bytes(1234) with struct.pack("!H", 1234). The first just provides a 4-byte string representation of the number bytes object with 1,234 null bytes; the second provides a …

  10. struct objects in python - Stack Overflow

    Oct 13, 2016 · In addition, a struct is nothing but a class with public members (i.e., struct{}; and class{public:}; are the exact same thing (in, say, C++)). Shouldn't you consider this and avoid artificial …