[New-bugs-announce] [issue16349] Document whether it's safe to use bytes for struct format string

Thomas Kluyver report at bugs.python.org
Sun Oct 28 13:43:42 CET 2012


New submission from Thomas Kluyver:

At least in CPython, format strings can be given as bytes, as an alternative to str. E.g.

>>> struct.unpack(b'>hhl', b'\x00\x01\x00\x02\x00\x00\x00\x03')
(1, 2, 3)

Looking at the source code [1], this appears to be consciously accounted for. But it doesn't seem to be mentioned in the documentation. I think the docs should either say it's a possibility, or warn that it's an implementation detail.

[1] http://hg.python.org/cpython/file/cde4b66699fe/Modules/_struct.c#l1340

----------
components: Library (Lib)
messages: 174042
nosy: takluyver
priority: normal
severity: normal
status: open
title: Document whether it's safe to use bytes for struct format string

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


More information about the New-bugs-announce mailing list