AnsweredAssumed Answered

searchcursor to compare records

Question asked by BLomas on Mar 22, 2016
Latest reply on Mar 22, 2016 by BLomas

I'm new to python so forgive me if this seems like an easy question... I want to compare fields of an mdb and a FC to identify inconsistencies. Also, the field names do not match. So, I have a script using a searchcursor and lists. Right now the script runs but it only seems to run on the first field and I need it to loop through 12 total. Any ideas on how to keep the loop running through all the fields?


from time import strftime  
print "Start script: " + strftime("%Y-%m-%d %H:%M:%S")  
import arcpy  
sourceFC = "M:\...\January2015Ownership"
# Use list comprehension to build a dictionary from a da SearchCursor  
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}  
updateFC = "M:\...\TaxParcel_COPY"

with arcpy.da.SearchCursor(updateFC, updateFieldsList) as originalRows:  
        for originalRow in originalRows:
            # store the Join value of the row being original in a keyValue variable  
            keyValue = originalRow[0]  
            # verify that the keyValue is in the Dictionary  
            if keyValue in valueDict:
                   for n in range (1,len(sourceFieldsList)):  
                        if originalRow[n] != valueDict[keyValue][n-1]:
                            print(str(keyValue) + ' was Changed in field "' + sourceFieldsList[n] + '"')
                print(str(keyValue) + ' check')
del valueDict  
print "Finished script: " + strftime("%Y-%m-%d %H:%M:%S")