This module converts between Python values and C structs represented as Python bytes objects
Structs em C
Exemplo:
from struct import unpack
data = b'Dremond \x19\x00\xaa\x00'
name, age, height = unpack('<10sHH', data)
struct Person
{
char name[10];
unsigned int age;
unsigned int height;
}
Funções
Notação do format
struct + namedtuple
os cascas de bala
namedtuple
Método _make
Combinando os dois
from struct import unpack
from collections import namedtuple
data = b'Dremond \x19\x00\xaa\x00'
Person = namedtuple('Person', ['name', 'age', 'height'])
person = Person._make(unpack('<10sHH', data))