I wrote an if elif statement that will loop through records (field A) and populate a new field (field B) based on A's contents.

Field A name is 'CLASS'. Field B is 'class_desc'.

def reclass(class_desc, CLASS):
 if CLASS == '100':
  return "100 - Agricultural"
 if CLASS == '105':
  return "105 - Agricultural Vacant Land (Productive)"
 elif CLASS == '110':
  return "110 - Livestock and Products"
 elif CLASS == '111':
  return "111 - Poultry and Poultry Products: eggs, chickens, turkeys, ducks and geese"
 elif CLASS == '112':

This 'completes successfully' but does not fill field B.

What am I doing wrong?

Obviously there is something fundamental that I cant get through my head about functions syntax.

  • 1
    It's possible you've created the field with a numeric type, but you're trying to insert text. In this case it just won't enter the value into the field.
    – RoperMaps
    Apr 26, 2018 at 17:23

1 Answer 1


'100' is text, 100 is integer so

 if CLASS == '100':

will never be true if CLASS field is of integer type. Change to:

 if CLASS == 100:

And you dont need to include class_desc since you dont use it in the function. You can also use a dictionary and save some typing:

def reclass(CLASS):
    d = {100:"100 - Agricultural", 105:"105 - Agricultural Vacant Land (Productive)", 110:"110 - Livestock and Products", 111:"111 - Poultry and Poultry Products: eggs, chickens, turkeys, ducks and geese"}
    if CLASS in d:
        return d[CLASS]
        return "Class not found"

Call the function on field class_desc with:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.