Select to view content in your preferred language

write GUID using Python

5093
1
05-12-2010 01:20 PM
KalleKronholm
New Contributor
I have a feature class with a GUID field. I would like to use Python to write a GUID (copied from a GlobalID) to this field. How do I do that? I have tried several possibilities, but all seem to fail.

Kalle
1 Reply
RussellBrennan
Esri Contributor
Hi Kalle,

Try this:

fc = 'TEST.russellpythonguidtest'
rows = arcpy.UpdateCursor(fc)
for row in rows:
     row.PYTHONGUID = row.GlobalID
     rows.updateRow(row)
Here is an option if you want to have a GUID that is unique from the GlobalID.
import uuid
fc = 'TEST.russellpythonguidtest'
rows = arcpy.UpdateCursor(fc)
for row in rows:
     row.PYTHONGUID = '{' + str(uuid.uuid1()) + '}'
     rows.updateRow(row)

There is some more doc here on using UUIDs with Python. You can use uuid4() to get a more random assignment.  http://docs.python.org/library/uuid.html