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

Ian Cordasco graffatcolmingov at gmail.com
Wed Sep 10 16:24:46 CEST 2014


On Wed, Sep 10, 2014 at 6:54 AM, Wolfgang Maier
<wolfgang.maier at biologie.uni-freiburg.de> wrote:
>> I can see use-cases for both. After less than two minutes of thought, it
>> seems to me that perhaps the most obvious APIs for these two different
>> representations are:
>>
>> hex(b'Abc') --> '0x416263'
>
>
> This would require a change in the documented
> (https://docs.python.org/3/library/functions.html#hex) behavior of hex(),
> which I think is quite a big deal for a relatively special case.

I agree that we should leave hex alone.

>> b'Abc'.decode('hexescapes') --> '\x41\x62\x63'
>
>
> This, OTOH, looks elegant (avoids a new method) and clear (no doubt about
> the returned type) to me.
> +1

Another +0.5 for me. I think this is quite elegant and reasonable. I'm
not sure it needs to be unicode though. Perhaps it's too early for me,
but does turning that into a unicode string make sense?


More information about the Python-ideas mailing list