[issue17617] struct.calcsize() incorrect

Mark Dickinson report at bugs.python.org
Tue Apr 2 15:34:06 CEST 2013


Mark Dickinson added the comment:

This is working as designed: the result of struct.calcsize matches the length of the string that you'll get back from struct.pack using that format.  Padding isn't included after the last entry in the struct.

That's not to say that it was a good design decision, but that's the design that was chosen, and it's not realistic to change this for the bugfix releases.  It may be possible to do something for Python 3.4.

You can add a '0L' to the end of your struct to force padding bytes at the end.  See:

http://docs.python.org/2/library/struct.html#examples

for an example of this.

See also #7189, #5145.

----------
nosy: +mark.dickinson
versions: +Python 3.4 -Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17617>
_______________________________________


More information about the Python-bugs-list mailing list