I cannot figure out why I keep getting this "StopIteration: iteration not started"error. I have confirmed the feature class 'vriTHLB_eliminated' exists and has records and all required fields.

Here is a simplified version of my code:

fieldList = ["SPECIES_CD_1","area_ha"]
with arcpy.da.UpdateCursor(vriTHLB_eliminated,fieldList) as cursor:` 
    for row in cursor:
        if row[0] == None or row[0] == "":  # If species 1 is null / absent / or empty string;
             cursor.deleteRow()             # delete these rows, they do not help with analysis.

        cursor.updateRow(row) #this definitely does need to indented inside the loop like this
del row, cursor

It looks like you're deleting a row if conditions are met, and then trying to update the same row following, which no longer exists. You can't update a row after it's been deleted.


fieldList = ["SPECIES_CD_1","area_ha"]

with arcpy.da.UpdateCursor(vriTHLB_eliminated,fieldList) as cursor:
    for row in cursor:
        if row[0] == None or row[0] == "":  # Simpler code is: if not row[0]:
        #### do other stuff here
  • Thanks Emil, but for clarity I have edited my code down to the basics.. there's actually about 100 lines in there, so many other branches. Some rows are deleted outright, most have a field value calculated based on other fields. I think the problem is with the branching logic; when my script reaches the cursor.updateRow(row) , I guess it's saying "I can't update this row in the FC because you haven't iterated anything yet". – grego Sep 19 '17 at 20:24
  • I've edited my response by adding a continue. – Emil Brundage Sep 19 '17 at 22:02
  • Thanks! This is gold. The continue keyword is totally what I needed to allow me to delete these rows at the top of the "for row in cursor" loop, before continuing to calculate other fields in each row, ending each iteration with a properly-indented cursor.updateRow(row) – grego Sep 19 '17 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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