2

I am trying to update attributes in a table using Calculate Field in Model Builder. I have used the following bit of code but its not updating the field.

    expression:
    Change(!Zone!)

    def Change(Zone):
      if (Zone == "NULL"):
      return "Non UK"

2 Answers 2

2

You need to indent the last line as such:

expression:
Change(!Zone!)
def Change(Zone):
  if (Zone == "NULL"):
    return "Non UK"

BUT what if Zone is not null? I assume you want to return it's value? Thus the code should be:

expression:
Change(!Zone!)
def Change(Zone):
  if (Zone == "NULL"):
    return "Non UK"
  else:
    return Zone
2
  • For some reason, that doesn't work. All the <null> values are still the same. The tool works in model builder, but the attributes are not updated.
    – MacroZED
    Commented Mar 16, 2016 at 17:20
  • Are well now you are saying something completely different which is <Null> and not the string "NULL". You will want to replace if (Zone == "NULL") with if Zone is None:
    – Hornbydd
    Commented Mar 16, 2016 at 17:32
2

Try this

    def Change(Zone):
        if not(Zone):
           return "Non UK"

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.