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

Terry Reedy tjreedy at udel.edu
Wed Sep 17 04:08:14 CEST 2014


On 9/16/2014 4:09 PM, Andrew Barnert wrote:

> the proposal is to extend `bytes.__format__`

Currently bytes just inherits object.__format__
 >>> bytes.__format__.__qualname__
'object.__format__'

object.__format__ does not allow a non-empty format string.

 >>> 'a{}b'.format(b'c\xdd')
"ab'c\\xdd'b"
 >>> 'a{:a}b'.format(b'c\xdd')
Traceback (most recent call last):
   File "<pyshell#26>", line 1, in <module>
     'a{:a}b'.format(b'c\xdd')
TypeError: non-empty format string passed to object.__format__

 > in some way that I don't think is
> entirely decided yet, but it would look something like this:
>
> u'Hello, {:a}'.format(some_bytes_var)  --> u'Hello, <whatever>'
>
> Or:
>
> u'Hello, {:#x}'.format(some_bytes_var) --> u'Hello,
> \\x2d\\x78\\x68\\x61...'




-- 
Terry Jan Reedy



More information about the Python-ideas mailing list