AnsweredAssumed Answered

Trying to use dictionary key with UpdateCurosor

Question asked by 2CQuiker on Oct 9, 2020
Latest reply on Oct 9, 2020 by 2CQuiker

I can do it with a basic arcpy.da.UpdateCurosr but I am trying to figure out how to use arcpy.da.UpdateCurosr with dictionary key. I am trying to populate Field1 if the row is blank but if not then continue on to the next row. I have the following but I get error,


upd_row[0] = search_feats[upd_row[1]] #FIELD_2
KeyError: 'Blah Text'


flds = ['Field1','Field']
search_feats = {f[0]:f[1:] for f in arcpy.da.SearchCursor(fc1, flds)}

with arcpy.da.UpdateCursor(fc1, flds) as upd_cur:
     for upd_row in upd_cur:
        #if upd_row[0] is None:
        if upd_row[0] != None:
        #if upd_row[0] in ("", ' ', None):              
            upd_row[0] = search_feats[upd_row[1]] #FIELD1

del upd_cur