Strange extra f added to bytes object

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Oct 6 21:07:31 EDT 2013


On Sun, 06 Oct 2013 20:39:39 -0400, Ned Batchelder wrote:

> When Python displays a string, is uses

A byte string.

> the ASCII character if it can, and a hex escape if it can't.  When you
> use a hex value that is a valid ASCII character, it will display the
> character.

Obviously for Python 2 that behaviour can't change, but I am saddened 
that the opportunity to fix the display of byte strings in Python 3 
wasn't taken. In my opinion, it would have been much better if byte 
strings were always shown in hex. (They could also have a separate method 
for showing them in ASCII, if necessary, but even that is only one call 
to decode() away.)

Displaying a *byte* string using ASCII by default just continues the 
confusion that many people have, that the character "f" is necessarily 
the same as the byte 0x66. *And* it leads to the OP's error, wondering 
why his byte-stream of 0x66... displays with a strange 'f'.

If you ask me, including ASCII in the printable representation of byte 
strings in Python 3 is buggy by design :-(


-- 
Steven



More information about the Python-list mailing list