From docs
Filling is only automatically added between successive members of the structure. No additive is added at the beginning or end of the encoded structure.
If you test
>>> import struct >>> s1 = struct.Struct('B') >>> print s1.size 1 >>> s1 = struct.Struct('f') >>> print s1.size 4
So, when you add it, 25 ... But on the contrary, B is 1, and the rest 4 , so it will be complemented to make it 4 , so the answer is 28 Consider this example
>>> s1 = struct.Struct('Bf') >>> print s1.size 8
Here again, B is 1 , and padded 3 and f are 4 , so it reaches 8 , which is as expected.
As mentioned here , to override it, you will have to use non-native methods
>>> s1 = struct.Struct('!Bf') >>> print s1.size 5
No additive is added when using step size and alignment, for example. with '<,'>, '=, and' !.
Bhargav rao
source share