3

I'm am trying to use a searchcursor to identify a list of ID's from a dataset. Using the list, I am now trying to delete those rows with the same ID's in another dataset.

I'm not sure where I'm going wrong.

rtc_id_values = []
with arcpy.da.SearchCursor(rtc_shp, "ID") as scursor:
    for srow in scursor:
        rtc_id_values.append(srow)

with arcpy.da.UpdateCursor(corporate_rtc_dataset, "ID") as ucursor:
    for urow in ucursor:
        if urow in rtc_id_values:
            row.deleteRow()
5

You've forgotten the indexes:

rtc_id_values.append(srow[0])

...

if urow[0] in rtc_id_values: 

Currently you're using entire row objects, not field values.

1

You can improve the efficiency of your code with a list comprehension:

rtc_id_values = [row[0] for row in arcpy.da.SearchCursor(rtc_shp, "ID")]

with arcpy.da.UpdateCursor(corporate_rtc_dataset, "ID") as ucursor:
    for urow in ucursor:
        if urow[0] in rtc_id_values:
            row.deleteRow()

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.