AnsweredAssumed Answered

FieldCalculate Feature Class Attribute values by matching existing field values to dictionary

Question asked by william.kalande_FPCWA on Mar 4, 2019
Latest reply on Mar 6, 2019 by

I have a dictionary whose keys also appear are attribute values in a fc_1.

In the code below, I use the dictionary values to select by attribute rows (gid) in fc_1 with intention of writing the dictionary keys into another field in fc_1 using arcpy.SelectLayerByAttribute_management.


This only writes the last key in the dictionary against all the selected values.


import arcpy

arcpy.env.workspace = r'home\delete\cccgdb.gdb'
gc = 'fc_1'
field ='FIDF'
dictio={"a": "AAA", "b": "BBB", "c": "CCC", "d": "DDD"}
fc_1_lyr = arcpy.MakeFeatureLayer_management(gc, "fc_1_lyr")
for i in dictio.keys():
     for j in dictio.values():
         #print (j)
         whereClause = "gid = '%s'"%j
         print (whereClause)
         act = arcpy.SelectLayerByAttribute_management(fc_1_lyr, 'NEW_SELECTION', whereClause)
         expression ='%s'%i
         arcpy.CalculateField_management(act, field, expression)
         arcpy.SelectLayerByAttribute_management(fc_1_lyr, "CLEAR_SELECTION")

print ('memaliza')

What am I doing wrong?