edit: After looking at the comic here is a more complete solution for XKCD geohashing:
>>> md5 = hashlib.md5('2005-05-26-10458.68').hexdigest() # get MD5 as hex string
>>> float.fromhex('0.' + md5[:16]) # first half as float
0.85771326770700229
>>> float.fromhex('0.' + md5[16:]) # second half as float
0.54454306955928211
Here is a more general answer for "converting to MD5 and then to decimal":
Say you want the decimal MD5 of the string 'hello world'
, you could use the following:
>>> int(hashlib.md5('hello world').hexdigest(), 16)
125893641179230474042701625388361764291L
The hash.hexdigest()
function returns a hexadecimal string, and int(hex_str, 16)
is how you can convert a hexadecimal string to a decimal.