Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What's the best way to get the OBJECTID name of a feature class?

I know you can use "OID@" in a cursor to get the field, but can you get the name from that as well?

I'm writing a script, and need to take into account varying OBJECTID names, like OBJECTID_2, OBJECTID_12, FID, etc. that will be used in a query.

Is using Describe the only way to get the name?

For example:

oid_field = [ for field in arcpy.ListFields("FC") if field.type == "OID"]

I'm just wondering if there's another way.


share|improve this question
up vote 8 down vote accepted

I would say that using describe is the best

oid_fieldname = arcpy.Describe(fc).OIDFieldName

is quite straightforward. Otherwise, you can directly filter when you use listFields, so you could try

oid_fieldname = arcpy.ListFields(fc,"","OID")[0].name

but this will return an error if there is no oidField (unlikely, but...)

share|improve this answer
I agree it is very straightforward. I've just noticed Describe can be a bit slow. Thanks. – ianbroad Jul 9 '14 at 18:04
@ian yes, thanks, I have updated – radouxju Jul 9 '14 at 18:24

Examine the code example in the help files The describe object and the OIDFieldName property will allow you to get its name if it has one

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.