Skip to main content
6 of 7
deleted 1816 characters in body; edited tags; edited title
saoirse
  • 246
  • 2
  • 13

Update Cursor with Lists as Dictionary

I have a field, "Access" that I want to populate with 4 variables based on the attribute of another field, "Des_Tp".For example, if a feature has "Des_Tp" = 'NP', then I would want to code it as open access, 'OA' in the field "Access".

I've put the lists in a dictionary, but the code runs without any change in the data:

import arcpy
from arcpy import env

arcpy.env.overwriteOutput = True

inFeatures = r"C:\Users\A\AccessTest.gdb\Access_test"
destp_dict ={1:("NP","NM","NCA","NF","NG","PUB","NT","WSR","NRA","NLS","IRA","ACEC","REC","RMA","ACC","OCS","SP","SREC","SLHCA","SRMA","LP","LREC","LHCA","LRMA"),
2:("NWR","WA","WSA","NSBV","RNA","REA","HCA","SDA","SW","SCA","LCA"),
3:("MPA","PROC","FOTH","ND","TRIBL","SO","LO","UNK"),
4:("WPA","MIT","MIL","PCON","PREC","PHCA","PAGR","PRAN","PFOR","PO","PO","CONE","RECE","HCAE","HCAE","AGRE","RANE","FORE","OTHE","UNKE")}

fields = ['Des_Tp', 'Access']

arcpy.MakeFeatureLayer(inFeatures, "TEMP_LYR")

with arcpy.da.UpdateCursor ("TEMP_LYR", fields) as cursor:
    for row in cursor:
        if row[0] == destp_dict[1]:
            row[1] = "OA"
        if row[0] == destp_dict[2]:
            row[1] = "RA"
        if row[0] == destp_dict[3]:
            row[1] = "UK"
        if row[0] == destp_dict[4]:
            row[1] = "XA"
        cursor.updateRow(row)
saoirse
  • 246
  • 2
  • 13