I want to get a list of all GUID fields in a feature class, but it seems that arcpy.ListFields is listing my GUID field as a SmallInteger. What am I doing wrong?
global_id_fieldnames = [f.name for f in arcpy.ListFields(layer) if f.type.lower() == 'guid']
after this list was empty, I called arcpy.AddMessage() for each of the fields:
for f in arcpy.ListFields(layer):
arcpy.AddMessage('{},{}'.format(f.name, f.type))
Answer
I emailed esri support and got this response:
There is a known bug (#NIM055662) for this behavior: [#NIM055662 ListFields and Describe methods are returning SmallInteger FieldType for GUID fields.]
The work-around is to check the field length; if it is longer than a standard "small integer" length, it's a GUID. Field type for a GlobalID field is SmallInteger with length 38 in my test case, much longer than the number of digits in a small integer. A small integer length may vary depending on the platform (although probably not on a Windows platform), but it would not be as large as 38.
following esri's advice, I'm now using:
global_ids_fields = [f.name for f in arcpy.ListFields(layer) if f.type.lower() == 'smallinteger' and f.length == 38]
No comments:
Post a Comment