1

I've tried writing a code block using the Python Parser of the ArcGIS Field Calculator. Here's what I am trying to achieve: There's a field in my attribute table with values for some, but not all of the polygons in the feature class. For those which have a Null Value I need to calculate the values using two other fields and a simple fraction. So the logic should be like this: If Field1 = Null, new value is Field2 / Field3, else Field1=Field1

I've written a script, but it won't work. It does compute, but there are either no results (meaning that the Null value stays like it is) or, in some cases for some reason, the new value is 1. This is the script, can anybody see the error? enter image description here

0

1 Answer 1

4

Try to change your code to

def calc(Wert1, Wert2, Wert3):
    if (Wert1 == None):
        return Wert2/Wert3
    else:
        return Wert1
2
  • 1
    Yes, I think it's the quotes around Null that are the problem. The quotes make it a string, so your code is checking literally for a string that says <Null> exactly, instead of an empty value, which in Python is expressed as None (without the angle brackets). Commented Jul 23, 2016 at 18:19
  • Thank you for your answers. I'll try it out on Monday when I'm back at the office and let you know how it works.
    – Username
    Commented Jul 23, 2016 at 19:59

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.