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 != valueDict[keyValue][n-1]:
print(str(keyValue) + ' was Changed in field "' + sourceFieldsList + '"')
break
else:
print(str(keyValue) + ' check')
break
del valueDict
print "Finished script: " + strftime("%Y-%m-%d %H:%M:%S")
Solved! Go to Solution.
Well, I knew it had to be something easy. I removed the "break" after the if and else statement and it seems to run on all the fields now. I still have a little work to do on the script but I appreciate the help and fast responses.
After changing the path names to raw path strings, I am still getting the same issue. The script will run but it seems to only go through the first field when I know there are more inconsistencies in other fields. I think the issue might be in the loop.
In fact, both feature classes should use raw notation (ie line 7)
Well, I knew it had to be something easy. I removed the "break" after the if and else statement and it seems to run on all the fields now. I still have a little work to do on the script but I appreciate the help and fast responses.