I'm pretty new to scripting with Python.
My code is intending to iterate through a list of feature classes within a GDB, creating the fields EF_Type and EF_Group, then calculating the field. The values of 'EF_Group' will be dependent on the values of EF_Type (ex: the feature classes 'Local EOCs' and 'State EOCs' will both have the value of 'EOC' in the 'EF_Group' field.
I created an update cursor to iterate through the feature classes and update the values of 'EF_Group.' The script runs without an error message, but when I open the attribute tables within Pro, 'EF_Group' remains NULL.
Code:
arcpy.AddField_management (fc, 'EF_Type', 'TEXT')
EFType = arcpy.CalculateField_management(fc, 'EF_Type', '"' + name + '"') #Renames field EF_Type to the first 2 words pulled using the split format tool
arcpy.AddField_management (fc, 'EF_Group', 'TEXT')
fields= ['EF_Type', 'EF_Group']
with arcpy.da.UpdateCursor(fc, fields) as cursor: #Update cursor will use 1st field (EF_Type) to build 2nd field (EF_Group)
for row in cursor:
if fields[0] == 'Local EOCs' or fields[0] == 'State EOCs':
fields[1] = 'EOC'
cursor.updateRow(row)
elif fields[0] == 'Fire Stations':
fields[1] = 'Fire'
cursor.updateRow(row)
elif fields[0] == 'Public Schools' or fields[0] == 'Private Schools' or fields[0] == 'DayCare Centers' or fields[0] == 'Colleges Universities':
fields[1] = 'School'
cursor.updateRow(row)
elif fields[0] == 'UrgentCare Centers' or fields[0] == 'Nursing Homes' or fields[0] == 'Hospitals Intersect':
fields[1] = 'Care'
cursor.updateRow(row)
elif fields[0] == 'LawEnforcement Locations':
fields[1] = 'Law'
cursor.updateRow(row)
row
object. You're only changingfields
, but you need to changerow
.fields[x]
torow[x]
wherex
is0
or1