Hello,
I'm have the following code trying to compare a field of different feature classes:
import arcpy
input_table = arcpy.GetParameterAsText(0)
input_fld = arcpy.GetParameterAsText(1)
compare_table = arcpy.GetParameterAsText(2)
compare_fld = arcpy.GetParameterAsText(3)
arcpy.AddMessage(input_fld)
#create a search cursor for the compare table
compare_cursor = arcpy.SearchCursor(dataset=compare_table, fields=compare_fld)
#create a set of all values in the compare cursor
compare_set = set()
for row in compare_cursor:
arcpy.AddMessage(row[0])
compare_set.add(row[0])
arcpy.AddMessage(compare_set)
#add a "compare field" if this is not already present
input_fields = arcpy.ListFields(input_table)
if not "Compare" in input_fields:
arcpy.management.AddField(input_table, "Compare", "TEXT")
#log if the value in the input fields exist in the compare table, by marking "yes" or "no" in the "compare" field
update_curs = arcpy.UpdateCursor(input_table, [input_fld, "Compare"])
for row in update_curs:
if row in compare_set:
row[0] = "YES"
else:
row[0] = "NO"
update_curs.updateRow(row)
This give me the following error, shouldn't a row in a search cursor be subscriptable by default?
field_compare
=====================
Parameters
Input Table E:\Users\58303\Documents\ArcGIS\Projects\test.gdb\Input_table
Input Field Input_field
Compare Table E:\Users\58303\Documents\ArcGIS\Projects\test.gdb\Compare_table
Compare Field Compare_Field
=====================
Messages
Start Time: Monday, August 12, 2024 2:39:21 PM
Input_field
Traceback (most recent call last):
File "E:\Users\58303\Documents\ArcGIS\Projects\Experimental.atbx#fieldcompare_NewToolbox.py", line 13, in <module>
TypeError: 'Row' object is not subscriptable
Failed script field_compare...
Failed to execute (fieldcompare).
Failed at Monday, August 12, 2024 2:39:21 PM (Elapsed Time: 0.43 seconds)