I'm attempting to delete some features from a feature class using an arcpy.da.UpdateCursor. The line uc.deleteRow() throws an exception with the message iteration not started.

The where_clause is "item_no in (123,456,789)"; return records with a value in this field found in this comma-delimited list. Here is the where clause being passed in ITEM_NO in (1,8,9).

To remove the where_clause as a possible source of this problem, I hard-coded a single value into the where; "item_no = 123". This also threw the error.

If I change this to a searchCursor using the same parameters, three records are returned, as expected.

with arcpy.da.UpdateCursor(fc, "OBJECTID", where_clause=strWhere) as uc:
    for row in XYZ:
        except Exception, e:
            print e

What am I doing wrong and how do I get around this?

  • uc.deleteRow(row) I think you actually need to pass the row as a parameter to the deleteRow method. – GeoJohn Jan 27 '17 at 20:22
  • @GeoJohn - I just tried that. deleteRow() takes no arguments (1 given) – DenaliHardtail Jan 27 '17 at 20:24
  • 2
    I'd lose the try/except while you are trying to debug. – PolyGeo Jan 27 '17 at 20:31

Your UpdateCursor is called uc but you're iterating through XYZ

for row in XYZ:

As a result it hasn't started iterating through your cursor to be able to delete anything. You need to reference your cursor:

for row in uc:
  • This is why you should be verbose in your variable naming. I feel the examples of ArcObjects don't always provide a good example of this. – John Grabanski Jan 27 '17 at 20:55

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.