Monday, July 02, 2007

Generate universally unique ID in Python

In my previous post, I discussed how to generate GUID (Windows world) or the standard equivalent UUID to generate a guaranteed unique identifier from Python. I didn't know that their is a CPython library that can do this in a more platform neutral way. Just today, I came across the module uuid. uuid is now part of the standard Python library but as to when, I am not sure. One thing I am certain, it is there in Python 2.5.1.


Below is a sample code to generate a UUID version 4.

import uuid

print uuid.uuid4()


If you want to know more about UUID and the standards using it, please pay a visit to Wikipedia - UUID.

~ts~

No comments: