[GIS] Advanced python labeling in ArcMap – working with null values

arcgis-10.1arcgis-desktoparcmaplabelingpython

I'm trying to label certain features using a specific field (osm_name_58_en). However, when this field is null, I want to label the feature with (som_english_32_name). If both are null then I want to label with the (amenity) field.

This is the code I'm trying but I'm not getting anything in return. Maybe I'm completely out to left field? I'm a python and advanced labeling newbie.

def FindLabel ( [amenity], [osm_english_32_name], [osm_name_58_en] ):
    if not ([osm_name_58_en] is None):
        return [osm_name_58_en]
    elif ([osm_name_58_en] is None and not([osm_english_32_name] is None)):
        return [osm_english_32_name] + '\n' + [amenity] 
    else:
        return [amenity];

Best Answer

The Correct form of your code is :

def FindLabel ( [amenity], [osm_english_32_name], [osm_name_58_en] ):
    if not ([osm_name_58_en] is None):
        return [osm_name_58_en]
    elif not([osm_english_32_name] is None):
        return [osm_english_32_name] + '\n' + [amenity] 
    else:
        return [amenity]

The semicolon in the last line is removed. and your elif statement is repaired

Related Question