Field Calculate syntax error

1426
10
01-14-2022 11:04 AM
2Quiker
Frequent Contributor

Trying to figure out a simple field calculate but I can't i keep getting syntax error. This is a shapefile.

 

I need to update the updateField field. The updateField is a text field.

 

def Reclass(SC):
    if (SC == "GR"):
        return = GRAIN
    if (SC == "WR"):
        return = WRITE
    if (SC == "PL"):
        return = PLACE

updateField = Reclass(!SC!)

 

0 Kudos
10 Replies
2Quiker
Frequent Contributor

Man I could not get the field calculator to work, I kept getting that I have a syntax error.

I ended up just using the python window with updatecursor.

 

import arcpy


fc = "layer"

with arcpy.da.UpdateCursor(fc,["SC","SC2"]) as cursor:
    for row in cursor:
        if row[0] not in (None, "", " "):
            if row [0] == "GR":
                row [1]= "GRAIN"
            elif row [0] == "WR":
                row [1] = "WRITE"
            elif row [0] == "PL":
                row [1] = "PLACE"
            cursor.updateRow(row)
        else:
            pass