python b'...' notation

Ian Kelly ian.g.kelly at gmail.com
Wed May 29 15:14:03 EDT 2013


On Wed, May 29, 2013 at 12:33 PM, alcyon <steve at terrafirma.us> wrote:
> This notation displays hex values except when they are 'printable', in which case it displays that printable character.  How do I get it to force hex for all bytes?  Thanks, Steve

Is this what you want?

>>> ''.join('%02x' % x for x in b'hello world')
'68656c6c6f20776f726c64'



More information about the Python-list mailing list