[issue10783] struct.pack() and Unicode strings

David Beazley report at bugs.python.org
Tue Dec 28 01:21:11 CET 2010


David Beazley <dave at dabeaz.com> added the comment:

I encountered this issue is in the context of distributed computing/interprocess communication involving binary-encoded records (and encoding/decoding such records using struct). At its core, this is all about I/O--something where encodings and decoding matter a lot.  Frankly, it was quite surprising that a unicode string would silently pass through struct and turn into bytes.  IMHO, the fact that this is even possible encourages a sloppy usage of struct that favors programming convenience over correctness--something that's only going to end badly for the poor soul who passes non-ASCII characters into struct without knowing it. 

A default encoding might be okay as long as it was set to something like ASCII or Latin-1 (not UTF-8).  At least then you'd get an encoding error for characters that don't fit into a byte.

----------

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


More information about the Python-bugs-list mailing list