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

Steven D'Aprano steve at pearwood.info
Thu Sep 11 11:51:01 CEST 2014


On Wed, Sep 10, 2014 at 11:47:01PM -0700, Chris Lasher wrote:

> Regarding user expectations, I've already stated, yes this continues with
> the expectations of experienced users, who won't stumble when they see
> ASCII in their bytes. For all other users, though, this behavior otherwise
> violates the principle of least astonishment. ("Why are there English
> characters in my bytes?")

That's easy to explain:

"Because Python gets used for many programming tasks where ASCII text is 
mixed in with arbitrary bytes, as a convenience for those programmers, 
as well as backward compatibility with the Bad Old Days, Python defaults 
to show bytes as if they were ASCII text. But they're not, of course, 
under the hood they're just numbers between 0 and 255, or 0 and 0xFF in 
hexadecimal, and you can see that by calling the hexify() method."


There are plenty of other areas of Python where decisions are made that 
are not necessarily ideal from a teaching standpoint. We cope.


-- 
Steven


More information about the Python-ideas mailing list