I tested it and got the same error, and I still don't understand why. But I found an easy workaround: Rename the dictionary to something else (without underscore) like symweights. Do that both in the code block and the expression field and it works.
That works perfect. Like Python should! Amazing. I choose this method, because I wanted to use the ModelBuilder. Not sure if a cursor would work in this case.
symbol_weights = { 6: 1.2, 85: 1.5, 2: 1.0, 42: 1.8, 58: 2.0, } cur = arcpy.UpdateCursor(my_feature_class) for row in cur: row.Weight = symbol_weights[row.SYMBOL] cur.UpdateRow(row)
Hi Ryan,
When you define the method within the Python codeblock, use a variable for the Reclass method's parameter and use that variable within the method's logic:
def Reclass(weight):
if (weight == 6):
return 1.2
elif (weight == 85):
return 85
.....
Then when you call the Reclass method in the Calculate Field Expression parameter, you will then pass in the SYMBOL field:
Reclass(!SYMBOL!)