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
2
  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])
2
  • Thank you so much! My skills are very basic with python at this point, so your clarification helps a lot. I didn't think about using the .format, that is genius! Great tip about formatting versus concatenating too, I'll have to remember that going forward. Thanks again for your help, it worked perfectly! Aug 27 at 12:49
  • @BrianMainor that's great, please read gis.stackexchange.com/help/someone-answers
    – user2856
    Aug 27 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.