Arcpy: Check if a field exists
I was helping a co-worker who needed to check if a field exists in their arcpy script. Since we were located at their computer, I thought I would just do a quick Google search and pull the code off this blog. Seemed logical since I the original purpose was exactly that—to serve as a handy, public place to store code snippets that I use & that others might find handy.
Anyhow, my Google Search on “Node Dangles field Exists” came up with a 9.3 script to check if field index exists. And I also have a 10.0 version but did not come up with the field exists snippet. So here it is:
def fieldExists(inFeatureClass, inFieldName):
fieldList = arcpy.ListFields(inFeatureClass)
for iField in fieldList:
if iField.name.lower() == inFieldName.lower():
return True
return False