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"
   
sourceFieldsList = ["PARCEL_","SITUS", "CURRENT_OWNER", "CO_OWNER", "OWNER_MAILADDR", "OWNER_CITY_STATE", "OWNER_ZIPCODE",  "TAX_DISTRICT", "TAX_CODE", "SEC", "TOWNSHIP", "RANGE", "LEGAL"]  
   
# 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"
   
updateFieldsList = ['PARCELID','SITEADDRESS','OWNERNME1', 'OWNERNME2', 'PSTLADDRESS', 'PSTLCITY', 'ZIPCODE', 'TAX_DIST',  'TAX_CODE', 'SEC', 'TWN', 'RGE', 'PRPRTYDSCRP']  
   

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] + '"')
                            break 
                       
            else:  
                print(str(keyValue) + ' check')
                break  
                      
del valueDict  
   
print "Finished script: " + strftime("%Y-%m-%d %H:%M:%S")

Outcomes