Arcmap Python Label Expression Function "Null"

8881
30
Jump to solution
11-02-2016 03:26 PM
DevinUnderwood2
Occasional Contributor

I am having difficulty with python parser label function to replace null values with "Unknown Plan" and leave everything else as is. The Unknown Plan is not displaying in the map label.

I have the following:

def FindLabel ( [PLAN] ):
    if  ([PLAN]) is  None:
         return "Unknown Plan"
    else:
        return [PLAN]

Any idea it is not working ?

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

This will treat NULL and empty strings the same way:

def FindLabel ( [PLAN] ):
    if  [PLAN] in  (None, ""):
        return "Unknown Plan"
    else:
        return [PLAN]‍‍‍‍‍‍‍‍‍‍

View solution in original post

30 Replies
DanPatterson_Retired
MVP Emeritus

line 2 the ( ) brackets aren't needed

line 3 is indented improperly

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Not to ask the obvious, but is the [PLAN] field an empty string instead of NULL?

0 Kudos
DevinUnderwood2
Occasional Contributor

I made Dan's suggested changes and still no luck.

I should of elaborated what string PLAN field is.  The blank fields are Null.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Nulls show up as <Null>, I think you have empty strings.

0 Kudos
DevinUnderwood2
Occasional Contributor

Good point, I have empty strings, how would I represent empty strings, not Null ?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

This will treat NULL and empty strings the same way:

def FindLabel ( [PLAN] ):
    if  [PLAN] in  (None, ""):
        return "Unknown Plan"
    else:
        return [PLAN]‍‍‍‍‍‍‍‍‍‍
DanPatterson_Retired
MVP Emeritus

Joshua... fix line 3... it bugs me

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Too bad it isn't SE, you could just fix it for me.

0 Kudos
DevinUnderwood2
Occasional Contributor
def FindLabel ( [PLAN] ):
    if  [PLAN] in  (None, " "):
        return "Unknown Plan"
    else:
        return [PLAN]

This work perfect, thank you. Good to know that an empty string treated the same for label expressions and the field calculator. Null is not though, having to use None to represent Null in label expressions.