how to turn arbitrary binary string into unix filename?
Fredrik Lundh
effbot at telia.com
Fri Feb 18 16:36:23 EST 2000
Bill Janssen <janssen at parc.xerox.com> 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:
# md5-example-2.py
import md5
import string
import base64
hash = md5.new()
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:
4c054aa3b6eda37560c57283b71046c3
TAVKo7bto3VgxXKDtxBGww==
...
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
names!
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list