I am new to Python. I am trying to write a script that will populate one field based on the contents of another field.

745
3
09-02-2014 10:24 AM
BrianHadley
New Contributor

I want the ZONE_DESC unit to be Agricultural 10 Acres if the ZONE unit is A-10. This is just the first part of the script. Later I will add if, elseif, and then statements to complete the script to assign the rest of the units of the ZONE_DESC field. when I run this portion of the script I get error messages. Am I close or I am way off?

Python.PNG

0 Kudos
3 Replies
AnthonyGiles
Frequent Contributor

try using a double equals:

f1 == "A-10"

a single = sign means you are trying to assign that value to the variable

0 Kudos
DarrenWiens2
MVP Honored Contributor

Your image shows that the parser is set to VB Script, which means it is expecting to read VB Script. Since you've written Python, change the parser to Python.

Also, you need to indent everything under the def statement.

0 Kudos
DanPatterson_Retired
MVP Emeritus

formatting issues...not checking logic issues

def calc(f1):

  if f1 == "A-10":

    a = "Agricultural 10 Acres"

  elif f1 == "something else":

    a = "not"

  else:

    a = "still not"

  return a

  

or in the field calculator (untested)

"Agricultural 10 Acres" if !Zone! == "A-10" else "False"

0 Kudos