how to turn arbitrary binary string into unix filename?

Fredrik Lundh effbot at
Fri Feb 18 16:36:23 EST 2000

Bill Janssen <janssen at> wrote:
> But after half an hour of poking around, I can't see a
> standard method that one can call to hexify a string.

well, you could have written one from scratch in much
less than 30 minutes, right? ;-)

here's some sample code from the eff-bot guide:


import md5
import string
import base64

hash =
hash.update("spam, spam, and eggs")

value = hash.digest()

print string.join(map(lambda v: "%02x" % ord(v), value), "")
print base64.encodestring(value)


running this prints:



alternatively use "sha" instead of "md5"; sha instances
have a hexdigest method that does exactly what you
want.  gives you a stronger digest, and even longer file


<!-- (the eff-bot guide to) the standard python library:

More information about the Python-list mailing list