Monday, 15 August 2016

editing - Using arcpy.da.Editor correctly?


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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...