Friday, 6 May 2016

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


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]

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)):

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...