[New-bugs-announce] [issue20803] struct.pack_into writes 0x00 for pad bytes

Andrew P. Lentvorski, Jr. report at bugs.python.org
Fri Feb 28 10:17:29 CET 2014

New submission from Andrew P. Lentvorski, Jr.:

This code did something unexpected to me:
>>> a = bytearray('1234')
>>> a
>>> struct.pack_into('xBxB', a, 0, 0x59, 0x5A)
>>> a

The unexpected part was that the 'x' pad byte formatter actually *overwrote* the bytes to 0 rather than leaving them alone.

Not necessarily a bug, but the fact that the pad byte writes 0x00 rather than being untouched/ignored should be documented.

components: Interpreter Core
messages: 212416
nosy: bsder
priority: normal
severity: normal
status: open
title: struct.pack_into writes 0x00 for pad bytes
type: behavior
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list