More

If-else logic expression in field calculator

If-else logic expression in field calculator


I want to calculate the value of a new field using an if-else condition with field calculator in modelbuilder. Want I want to do is as follows: if my new field is empty, then use the expression entered by the user to calculate the value of the field; else do nothing and keep it as it is.

What I have done so far is the following:


I wouldn't use the function name 'Reclass', I think that may already be the name of an existing function.

But basically, 'OR CODE Value" is not correct. It's not clear exactly what you want to do. It looks like you just want to return the same value you're passing in. You're returning the existing OR_CODE value when OR_CODE is an empty string, and it looks like you want to return the existing OR_CODE value value when it's not. So it looks like you just want to calculate the same value as already exists either way, which seems kind of pointless. Maybe what you want is to return some different value when OR_CODE =", otherwise keep the existing value. Try something like this:

def rcls(someCode, otherValue): if someCode ==": return otherValue # or, calculate a value else: return someCode OR_CODE = rcls(!OR_CODE!, 'someOtherValue')

Watch the video: Python in the Field Calulator