0

I am having difficulty wrapping my brain around the point of the expression vs the code block. What am I suppose to be defining? I copied the example from calculate value in the ArcGIS help website almost verbatim and yet it says my definition is wrong. More specifically it says a syntax error in line 1.

simple if else statement

  • 3
    In a python code block it should be fn(!Z_score!,!Z_top!), it looks like they're defined as a variable in your model, but those variables are out of scope for the code block, there shouldn't be any percents or exclamation marks in the code block. Please ensure you're using the python or python 9.3 parser and not VB (not seen on screen shot). I think it would be better to not populate the Data Type as it's optional; boolean certainly isn't correct. – Michael Stimson Sep 28 '17 at 1:08
  • 1
    Additionally, the variables in the code block don't need to be the same as the real-world variables. You could just call them Zscore and Ztop. Only the variables in the actual expression need to point to a variable. – Map Man Sep 28 '17 at 17:27
1

In your code block you are defining a function, in your expression you are calling that function. Your function needs to specify new variable names that are used within the function, and you pass the field names to those variables. The function variables should have new unique names, not the same values you are passing in your expression.

Code Block:

def fn(zs, zt):
    if zs => 0:
        return zs
    else:
        return zt

Expression:

fn(!Z_score!, !Z_top!)

So here you are passing the value from !Z_score! to your function into a variable called zs, and the value from !Z_top! into zt. Those values are then used in the function.

And as commented by Michael Stimson, leave the Data Type as blank as Boolean is unlikely to be the correct value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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