+ 2

Hello everyone, I can't really understand how the Struct functions work in python could someone give me some exemples? Thank you

As explained in the title, for example I can't understand this : Several struct functions (and methods of Struct) take a buffer argument. This refers to objects that implement the Buffer Protocol and provide either a readable or read-writable buffer. The most common types used for that purpose are bytes and bytearray, but many other types that can be viewed as an array of bytes implement the buffer protocol, so that they can be read/filled without additional copying from a bytes object. Source :https://docs.python.org/3/library/struct.html Could you explain me those functions : struct.pack(format, v1, v2, ...)¶ struct.pack_into(format, buffer, offset, v1, v2, ...)¶ struct.unpack(format, buffer)¶ struct.unpack_from(format, buffer, offset=0)¶ struct.iter_unpack(format, buffer)¶ struct.calcsize(format)¶ Some examples are given like >>> from struct import * >>> pack('hhl', 1, 2, 3) b'\x00\x01\x00\x02\x00\x00\x00\x03' >>> unpack('hhl', b'\x00\x01\x00\x02\x00\x00\x00\x03') (1, 2, 3) but I can't understand.

26th Mar 2019, 4:33 PM
Maximilien
Maximilien  - avatar
2 Antworten
+ 3
Read about DATA STRUCTURES
26th Mar 2019, 11:07 PM
Da2
Da2 - avatar
+ 1
Okay 👌 thank you
27th Mar 2019, 6:16 AM
Maximilien
Maximilien  - avatar