On 10 September 2014 15:24, Ian Cordasco graffatcolmingov@gmail.com wrote:
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?
It's easy enough to do by hand:
print(''.join("\x{:02x}".format(c) for c in b'Abc'))
\x41\x62\x63
And you get any other format you like, just by changing the format string in there, or the string you join on:
print(':'.join("{:02x}".format(c) for c in b'Abc'))
41:62:63
Not every one-liner needs to be a builtin... Paul