[Q]:Generate Unique ID's
Joe Francia
usenet at soraia.com
Fri May 23 18:05:16 EDT 2003
achrist at easystreet.com wrote:
> I'd like to generate unique identifiers for database items,
> sort of like the ID's that MS uses for COM. My purpose is
> to have unique ID's (across multiple [distributed] installations of
> a program), so that databases can be combined, copied, carried off,
> re-acquinted, compared, re-synchronized, etc, with some prayer
> of not being totally munged.
>
> Is there anything in the standard Python libs to generate an ID
> like those that Windows uses, which are guaranteed to be unique
> over all instances of everything, forever, no exceptions? How
> about an easy call to Windows (if I don't care about cross-platform)
> to have it generate one for me? As this might happen every time
> a user presses enter, maybe even several times on some updates,
> it would be nice if it never took more than (e.g.) 0.1 secs or so.
>
>
> Al
There's a CreateGuid() funtion in the pywintypes modules, which is part
of the ActiveState python distribution (which includes the Win32
Extensions):
>>> import pywintypes
>>> guid = pywintypes.CreateGuid()
>>> print guid
<iid:{9F0FF800-5596-4C91-BA8F-531973E8790A}>
>>> print str(guid)[1:-1]
'9F0FF800-5596-4C91-BA8F-531973E8790A'
More information about the Python-list
mailing list