Generate ID from string in Python
I would do something like this:
>>> import hashlib
>>> m = hashlib.md5()
>>> m.update("some string")
>>> str(int(m.hexdigest(), 16))[0:12]
'120665287271'
The idea:
- Calculate the hash of a string with MD5 (or SHA-1 or ...) in hexadecimal form (see module hashlib)
- Convert the string into an integer and reconvert it to a String with base 10 (there are just digits in the result)
- Use the first 12 characters of the string.
If characters a-f
are also okay, I would do m.hexdigest()[0:12]
.