[Python-ideas] Stop displaying elements of bytes objects as printable ASCII characters in CPython 3

Nick Coghlan ncoghlan at gmail.com
Wed Sep 10 09:34:34 CEST 2014


On 10 September 2014 17:04, Chris Lasher <chris.lasher at gmail.com> wrote:
> Why did the CPython core developers decide to force the display of
> ASCII characters in the printable representation of bytes objects in
> CPython 3?

Primarily because it's incredibly useful for debugging ASCII based
binary formats (which covers many network protocols and file formats).

Early (pre-release) versions of Python 3.0 didn't have this behaviour,
and getting the raw integer dumps instead turned out to be *really*
annoying in practice, so we decided the easier debugging justified the
increased risk of creating incorrect mental models for users
(especially those migrating from Python 2).

The recently updated docs for binary sequences hopefully do a better
job of explaining this "binary data with ASCII compatible segments"
favouritism in their description of the bytes and bytearray methods:
https://docs.python.org/3/library/stdtypes.html#bytes-and-bytearray-operations
(until a couple of months ago, those methods weren't documented
separately, which I agree must have been incredibly confusing).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list