0

I'm using ArcGIS Pro and am trying to create a label expression. I need the fields without data (NULL) to only say Name. Otherwise, I need it to say the name and the mounding data below it. This is my initial idea behind the code, but it currently doesn't work. The problem seems to be with the 'if' portion of the if / else statement.

def FindLabel ( [Name], [Mounding] ):
   
    out=""
   
    if [Mounding] is NULL
   
    out+= [Name]
   
    else
   
    out+= "<UND>"+"<BOL>"+[Name]+"</BOL>"+"</UND>"+"\n" + [Mounding]
 
    return out
0

1 Answer 1

3
  1. Use None not NULL. Python doesn't understand "NULL"
  2. Your if else is not valid python syntax, you need if: and else: with indented lines below each
  3. You don't need to add literal strings to literal strings "<UND><BOL>" not "<UND>"+"<BOL>"
  4. String formatting is faster than concatenating (adding)

    def FindLabel ( [Name], [Mounding] ):
             
        if [Mounding] is None:
            return [Name]
       
        else:
            return "<UND><BOL>{}</BOL></UND>\n{}".format([Name],[Mounding])
0

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.