[GIS] Using if/elif for passing null values to Python of label expression in ArcGIS for Desktop

arcgis-desktoparcmaplabelingpython

I am trying to pass the Null values in label expression in advance python section. I have this code and it's not working. Note that all my values in [TX_SECT] and [ABSTRACT] are numbers.

def FindLabel ( [TX_SECT], [ABSTRACT] ):
    if [TX_SECT] == "None" and [ABSTRACT] != "None":
        return [ABSTRACT]
    elif  [TX_SECT] != "None" and [ABSTRACT] ==  "None":
        return [ABSTRACT]
    elif [TX_SECT] == "None" and  [ABSTRACT] == "None":
        return ""
    else:
        return [TX_SECT] + '\n' + [ABSTRACT]

Best Answer

as your values [abstract] and [TX_sect] are number, you should return them as string using str([abstract])

Secondly, "None" will be a string, not the null value. You must test it with

[field] is None

Finally, your condition should be written in parenthesis :

if ([TX_SECT] is None and not([ABSTRACT] is None)):
Related Question