AnsweredAssumed Answered

Find matching attributes

Question asked by 2CQuiker on Oct 3, 2017
Latest reply on Oct 5, 2017 by CCweedcontrol

I am trying to update the points selected features field "Verifi2" with "Match" or "No" based on if the 'SiteAddres' field of the selected feature matches the parcels layer 'SiteAddress' field. I currently have the following code but all of the selected features have "No" in the Verifi2 field. Which is not the case because some of the selected point features SiteAddres does match parcels SiteAddress. I would appreciate some help please.

 

import arcpy 
from datetime import datetime as d
startTime = d.now()

fc1 = "AddresPointsTest"
fc2 = "TaxParcels1"

#set up cursors
cursor1 = arcpy.da.SearchCursor(fc1, ["SiteAddres", "Verifi2"]) 
cursor2 = arcpy.da.SearchCursor(fc2, ["SiteAddress"])


with arcpy.da.UpdateCursor(fc1, ["SiteAddres", "Verifi2"]) as cursor1: 
     for row1 in cursor1: 
          with arcpy.da.SearchCursor(fc2, ["SiteAddress"]) as cursor2: 
               row2 = cursor2.next() 
               #print row2 
               row1[1] = "Match" if row1[0].lower() == row2[0].lower() else "No" 
               #print row1[2] 
               cursor1.updateRow(row1) 

try:
    print '(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')'

except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message

Outcomes