I have a fairly small script which is running a cursor on a small feature class (~2500 features) which is crashing python with a python.exe has stopped working
message.
I have a cursor that loops over features, deletes any that don't meet a set criteria, looks up field value keys in a dictionary, and updates another field with the dictionary value. This works well. But if I add in a check to deleteRow()
any records that have a Null
or a value that doesn't start with the letter O
.
arcpy.FeatureClassToFeatureClass_conversion(r"mydatabase.sde\mydatabase.dbo.SitePolygon", "in_memory", "xTempPolygon")
with arcpy.da.UpdateCursor(r'in_memory\xTempPolygon', ['RecID', 'LotID', 'Owner', 'Manager', 'Class']) as cursor:
for row in cursor:
if row[2] != 'CITY' or row[4][:4].upper() == 'ROAD' or row[3].upper() in ['WASTEWATER', 'STORMWATER', 'WATERSUPPLY']:
cursor.deleteRow()
elif row[0] in resultDict:
row[1] = resultDict[row[0]]
cursor.updateRow(row)
#################################################
# If I add this block, it crashes
if row[1] is None or row[1][0].upper() != 'O':
cursor.deleteRow()
#################################################
The resultDict
is a dictionary that comes from a SQL lookup that returns RecID
and LotID
. These are looked up in the cursor and populates the LotID
on the feature based on its RecID
.
If I leave out the final if
block, it runs without issue. If I add it in it crashes. I need it there because I'm ending up with some records that have a NULL
or a value that doesn't start with O
in the LotID
field. I need these records deleted.
I need the extra if
to run after the update to allow for the update to run, as no records have any values in row[1]
before the update - they are all NULL
so they'd all be deleted.
What is causing this crash, and how do I avoid it?
row[1]
before the update