I am attempting to remove duplicates in a feature class that are generated by a Python script. At the end of my script I have the code block below; I haven't implemented it yet, but would like to see if this is the correct way to use arcpy.da.Editor as the errors that I have been receiving are in regards to being outside of an edit session.
Is arcpy.da.Editor being used correctly here?
`
fields = ['OBJECTID', 'SRNumber', 'ItemLoc_9']
table_rows = []
delete_rows = []
where_clause = """ ItemLoc_9 = ' '"""
with arcpy.da.Editor(appendClass) as edit:
with arcpy.da.SearchCursor(appendClass, fields, where_clause) as cursor:
for row in cursor:
if [row[1], row[2]] in table_rows:
delete_rows.append(row[0])
else:
table_rows.append([row[1], row[2]])
del table_rows
with arcpy.da.UpdateCursor(appendClass, ['OBJECTID']) as cursor2:
for row in cursor2:
if row[0] in delete_rows:
print 'Deleting record: OBJECTID = ' + str(row[0])
cursor2.deleteRow()
print '\ndone'`
No comments:
Post a Comment