[Python-ideas] Stop displaying elements of bytes objects as printable ASCII characters in CPython 3
Ron Adam
ron3200 at gmail.com
Thu Sep 11 18:42:24 CEST 2014
On 09/10/2014 09:40 PM, Nick Coghlan wrote:
> On 11 September 2014 11:36, Ron Adam<ron3200 at gmail.com> wrote:
>> >When working with hex data, I prefer the way hex editors do it. With pairs
>> >of hex digits separated by a space.
>> >
>> > "50 79 74 68 6f 6e" b'Python'
>> >
>> >But I'm not sure there's a way to make that work cleanly. :-/
> I realised (http://bugs.python.org/issue22385) we could potentially
> support that style through the string formatting syntax, using the
> precision field to specify the number of "bytes per chunk", along with
> a couple of the other existing formatting flags in the mini-language:
>
> format(b"xyz", "x") -> '78797a'
> format(b"xyz", "X") -> '78797A'
> format(b"xyz", "#x") -> '0x78797a'
>
> format(b"xyz", ".1x") -> '78 79 7a'
> format(b"abcdwxyz", ".4x") -> '61626364 7778797a'
> format(b"abcdwxyz", "#.4x") -> '0x61626364 0x7778797a'
>
> format(b"xyz", ",.1x") -> '78,79,7a'
> format(b"abcdwxyz", ",.4x") -> '61626364,7778797a'
> format(b"abcdwxyz", "#,.4x") -> '0x61626364,0x7778797a'
Is there a way to go in the other direction? That is these other hex
formats to bytes?
Ron
More information about the Python-ideas
mailing list