ListFields
returns a list
of field objects, and each of these objects has attributes associated with it.
So the structure looks like this:
field_list = [field object1: field.name, field.type, etc...;
field object2: field.name, field.type, etc...;
]
You'll probably want to access the .name
attribute of each field object to determine if it matches any name in the variable fieldList
.
First, generate a list of field names:
existingFields = [] # empty list
for field in arcpy.ListFields(inputFC): # iterate over fields
existingFields.append(field.name) # add the attribute name to list for each field
Next, compare the list of existing fields with the list of fields the user wants to add:
duplicateFields = set(existingFields) & set(fieldList)
if len(duplicateFields) == 0:
carry on with adding fields
else:
arcpy.AddMessage('Field(s) already exist: ' + duplicateFields)