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!)
If you're trying to return text, do you need quotes around your text returns?
I have tried it with quotes and still get the syntax error.
def Reclass(SC):
if (SC == "GR"):
return "GRAIN"
if (SC == "WR"):
return "WRITE"
if (SC == "PL"):
return "PLACE"
updateField = Reclass(!SC!)
Hello 2Quiker,
Does the syntax error identify a certain line of code?
I wonder if your return statements need to also be in quotations to be returned as text. "GRAIN" instead of GRAIN.
Cheers,
Mike
Total rookie mistake, I forgot to check the python parser box.
Oh no! Was it in vbscript or Arcade? At least you got it figured out!
It was in vbscript, so I though I had it figured out but I guess not. The following only works with one if but when adding more elif I get an error that field is not nullable. How do I handle Nulls and blanks in field calculator? The SC field dose have some nulls and blanks.
def Reclass(SC):
if (SC == "GR"):
return "GRAIN"
elif (SC == "WR"):
return "WRITE"
elif (SC == "PL"):
return "PLACE"
updateField = Reclass(!SC!)
What do you want to do with nulls? Leave them null? The python syntax for null is "None".
So you could write something like:
if SC is not None:
If (SC == "GR"):
return "GRAIN"
elif .... and so on
Using what you posted if SC is not None: but still have me the error "The field is not nullable". So I check the attributes filed and there are some blanks and nulls. I am trying to run this on the how feature class table not just the selected features.
def Reclass(SC):
if SC not in [None, "", " "]:
if (SC == "GR"):
return "GRAIN"
elif (SC == "WR"):
return "WRITE"
elif (SC == "PL"):
return "PLACE"
updateField = Reclass(!SC!)
def Reclass(SC):
if SC not in [None, "", " "]:
if (SC == "GR"):
return "GRAIN"
elif (SC == "WR"):
return "WRITE"
elif (SC == "PL"):
return "PLACE"
else:
return "grief a null"
you need to tell it what to do if there is one of those no-no cases