Getting hex value of a character

Daniel Dittmar daniel.dittmar at sap.com
Thu Dec 12 12:23:06 EST 2002


Dennis Reinhardt wrote:
> I am trying to print the hexadecimal value of a string.  In other
> words, the string "AB" would print as "4142".  I simply cannot get

string.join (
    map (lambda ch: '%02x' % ord (ch), stringvar),
    '')

The lambda formats one character as hex
the map aplies this to all characters
the join combines all the short strings into one

Daniel





More information about the Python-list mailing list