BloodSexMagik BloodSexMagik - 10 months ago 48
Python Question

Python struct format character sizes, why is it bigger than it should be?

Simple question if do the following:

import struct

returns 32 when I believe it should be 28.

By doing the following (missing the Q):

import struct

it returns 20, which is what I would expect.

and doing:

import struct

returns 8, which is correct.

Why does adding the Q onto the top one result in 12 extra bytes being expected instead of 8?

Python 3, windows machine.


Answer Source

Alignment. See for more details.

Try struct.calcsize("=6cHcBHIIQ").