I just tried using struct.pack in Python for the first time and I don't understand its behavior when I mix types
When I try to pack a single char and nothing else, it works as expected, i.e.
struct.pack("b",1)
gives '\x01' . But as soon as I try to mix data of another type, the char fills as long as this type, for example
struct.pack("bi",1,1)
gives '\x01\x00\x00\x00\x01\x00\x00\x00' .
Is this standard behavior and why? Is there any way around this?
Edit
Simply put:
>>> struct.calcsize("b") 1 >>> struct.calcsize("i") 4 >>> struct.calcsize("bi") 8
scozy source share