1

I am using ArcGIS Desktop 10.6.1. I create a new field of type short integer in the Attribute Table. My new field is named CIPOT and I want to populate it with values from the field CI, but only if values in field Z = 100, otherwise I want CIPOT to equal zero.

My Python script:

def NumValue( CI ):

  if (Z == 100):
    return CI
  else:  return 0

NumValue(!CI! )

Here is a screen shot:

enter image description here

I am getting an error message that global name 'Z' in not defined.

3
  • 6
    You need to pass in a variable into your function for Z. def NumValue(CI, Z): `NumValue(!CI!, !Z!)
    – Nathan W
    Commented Feb 18, 2019 at 23:16
  • 1
    !ci! If !z!==100 else 0 will work without block.
    – FelixIP
    Commented Feb 19, 2019 at 19:00
  • felixIP: that doesn't work. I get a syntax error.
    – TobyG
    Commented Feb 20, 2019 at 22:44

1 Answer 1

2

As @NathanW has commented, you have passed the value of your CI field to your function using defNumValue(CI):, but have not passed the value of the Z field.

You can pass the Z value by just adding it to your function variables

def NumValue(CI, Z):
    if (Z == 100):
        return CI
    else:  return 0

Expression:

NumValue(!CI!, !Z!)
0

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.