You are not logged in Log in Join
You are here: Home » Members » andym » Generating unique id's on windows

Log in
Name

Password

 

Generating unique id's on windows

Ever had to generate unique ids? If you are running on Windows one simple answer is the GUID generation system from Microsoft. There is simple access to this from Mark Hammond's Python Win32 extensions, these can be found at www.ActiveState.com.

# Andy McKay, 2002
# [email protected]
from pywintypes import CreateGuid

# this requires Mark Hammond's
# win32 api is installed
# this can be found at ActiveState
# or in ActivePython
def getUnique(self):
    pyiid = CreateGuid()
    # the str(pyiid) looks like {....}
    # doing [1:-1] strips that off
    return str(pyiid)[1:-1]

This will create a guid along the lines of: 5F6635D8-A1E2-4B36-AB19-FB2AA0B34570

You can either make an external method such as CreateGUID and call it from DTML such as CreateGUID. For those more who want it you could import pywintypes into a Script (Python). See the Script (Python) docs for more info.