Converting strings to hex

Guido van Rossum guido at python.org
Thu May 18 23:40:18 EDT 2000


Dale Strickland-Clark wrote:
> 
> The output from MD5.digest() is a 16 byte binary string.
> 
> I want to convert it to hex for printing.

It's hard to beat this, which uses only built-in operations:

def hexify(s):
    return "%02x"*len(s) % tuple(map(ord, s))

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list