how to print out each single char from a string in HEX format?

Troels Thomsen nejtak...
Tue Jun 5 23:12:34 CEST 2007



> Great! It works.
>

There is a builtin function called hex() that does the same, but also shares 
the same problem as the solution above:

>>> hex(10)
'0xa'
>>>

This is probably not "nice" in your printouts, it doesn't allign.


with the printf inspired solution you can set the precision like this:

>>> a = "12\n34"
>>> for c in a:
...   print "%#04x" % ord(c),
...
0x31 0x32 0x0a 0x33 0x34
>>>


regards troels





More information about the Python-list mailing list