<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Label Expression via Python in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1050090#M40054</link>
    <description>&lt;P&gt;Hi Pete.&amp;nbsp; Glad it worked out.&amp;nbsp; We can add those lines.&amp;nbsp; First though, here is a quick demo hopefully illustrating a few of the tougher tricks and functionality in that original code.&amp;nbsp; Run this using a Notebook in Pro.&amp;nbsp; Just cut and paste this into a cell and hit the Run arrow - see what prints.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;player = ['Steve Nash','Steph Curry', 'Kawhi']
stat = ['Assists','Threes','FG pctg']
num = [11,500,60]
apex_statistics = []
# zip basically runs a for loop with multiple lists simultaneously
for player, stat, num in zip(player, stat, num):
  # different formatting for fg pctg
  if stat in ['FG pctg']:
      num = '{}%'.format(num)
  # note this syntax (.format)is for more current Python versions.
  # Google / StackExchange from older posts will be similar but different
  # each {} will be populated by locationally matched item in ()  
  str = '{} master of {}:\n{} per year!'.format(player, stat, num)
  # add str to list one at a time each iteration of for loop
  apex_statistics.append(str)
# creates single string from the 3 strings in the list apex_statistics
full_str = '\n\n'.join(apex_statistics)
print(full_str)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;So to get the width string formatted, replace existing lines in if statement block for width with those shown below.&amp;nbsp; Note use either Option A or B (delete the other).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;  if [WIDTH] not in (None, "&amp;lt;NULL&amp;gt;", "0"):
    # option A basic
    width_str = 'Width: {}'.format([WIDTH])
    # option B - add units if you want too
    width_str = 'Width: {} Feet'.format([WIDTH])
    str_list.append(width_str)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;let me know if that works.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Apr 2021 14:32:24 GMT</pubDate>
    <dc:creator>ZacharyUhlmann1</dc:creator>
    <dc:date>2021-04-22T14:32:24Z</dc:date>
    <item>
      <title>Label Expression via Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1049679#M39967</link>
      <description>&lt;P&gt;&amp;nbsp; I'm not the greatest with Python so I can easily get confused with indentations and such among other things.&lt;/P&gt;&lt;P&gt;&amp;nbsp; Currently I want to create a label expression to do the following and am only able to get it to work with 2 conditions and not the 3rd.&lt;/P&gt;&lt;P&gt;Field Names&lt;/P&gt;&lt;P&gt;[NAME]&lt;/P&gt;&lt;P&gt;[ALT_NAME]&lt;/P&gt;&lt;P&gt;[WIDTH] = Numeric&lt;/P&gt;&lt;P&gt;&amp;nbsp; I want to display these 3 fields only if they are not null or any combination of them that aren't null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Originally I was only doing this with [NAME] and [ALT_NAME], and the code for this allows me to display either NAME or ALT_NAME or Both if they aren't (None, "", "&amp;lt;Null&amp;gt;"&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;def FindLabel ( [ALT_NAME], [NAME] ):
    if [ALT_NAME] in (None, "") or [ALT_NAME] in (None, "0"):
        return [NAME]
    
    elif [NAME] in (None, "") or [NAME] in (None, "&amp;lt;Null&amp;gt;"):
        return [ALT_NAME]
    
    else: 
      return [NAME] +'\r\n'+ [ALT_NAME]&lt;/LI-CODE&gt;&lt;P&gt;This works fine.&amp;nbsp; However when trying to add in the [WIDTH], I want it to only display that if it is not null or equal to 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp; So far I've been trying too many things to list on here and nothing seems to work.&amp;nbsp; I'm not sure if I'm indenting things wrong or using the&amp;nbsp;&lt;STRONG&gt;.strip()&lt;/STRONG&gt; wrong (either using it or not using it) and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp; I just want a code that only shows any combination or any of these that don't have blank or &amp;lt;Null&amp;gt; values (or 0 as well for the [WIDTH]).&lt;/P&gt;&lt;P&gt;&amp;nbsp; I know the code is probably a little messed up from the start, but again, I'm not all that familiar with Python...&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 16:59:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1049679#M39967</guid>
      <dc:creator>PeteJordan</dc:creator>
      <dc:date>2021-04-21T16:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Label Expression via Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1049853#M40007</link>
      <description>&lt;P&gt;Hi Pete.&amp;nbsp; I took a different approach with your desired outcome.&amp;nbsp; Let me know if this displays what you wanted (it worked for me with NAME and ALT_NAME type = string, and WIDTH type = int (or single?):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def FindLabel([NAME],[ALT_NAME],[WIDTH]):
  # initiate empty list to append to if val == NULL
  str_list = []
  if [NAME] not in (None, "&amp;lt;NULL&amp;gt;", "0"):
    str_list.append([NAME])
  if [ALT_NAME] not in (None,"&amp;lt;NULL&amp;gt;", "0"):
     str_list.append([ALT_NAME])
  if [WIDTH] not in (None, "&amp;lt;NULL&amp;gt;", "0"):
     str_list.append(str([WIDTH]))
  # create one string from all non-NULL values with "\n" in between
  label_str = '\n'.join(str_list)
  return(label_str)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My understanding is that you ONLY want to display labels for values that do NOT == 0, NULL, etc.&amp;nbsp; If that's not the case, we can adjust logic.&amp;nbsp; I honestly don't do fancy label action often, so thanks for showing me the "&amp;lt;NULL&amp;gt;" syntax.&amp;nbsp; Just curious, the "0" in (None, "&amp;lt;NULL&amp;gt;", "0") is actually a string not the integer 0.&amp;nbsp; If you want to hunt for the integer, then remove the "".&amp;nbsp; If you want both string and int, just add a comma and 0 within the parenthesis constructing your tuple.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if that worked for you...Zach&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 22:02:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1049853#M40007</guid>
      <dc:creator>ZacharyUhlmann1</dc:creator>
      <dc:date>2021-04-21T22:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Label Expression via Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1050049#M40042</link>
      <description>&lt;P&gt;That works Zach, thanks for that.&lt;/P&gt;&lt;P&gt;Now the next step would be to add some text for the width field to just say "Width = " and then the value.&lt;/P&gt;&lt;P&gt;In my original code&amp;nbsp;&lt;EM&gt;(not shown here)&lt;/EM&gt; I had&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;return [NAME] +'\r\n'+ [ALT_NAME] +'\r\n'+ "Width = " + [WIDTH] + "'"&lt;/LI-CODE&gt;&lt;P&gt;as my final line to at least have that text.&amp;nbsp; How would I add that to your script?&amp;nbsp; I tried to create a new string&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  str_Widthtxt = "Width = "&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;but wasn't sure how to add it to the&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;str_list.append(str([WIDTH]))&lt;/LI-CODE&gt;&lt;P&gt;line.&amp;nbsp; Tried using the + and then commas and various other things, but no luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Finally do you know how to italicize results or text in python in Pro?&amp;nbsp; &amp;nbsp;I swore I had done this in the past, but I'm not finding anything that works now and not sure if its even possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 12:57:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1050049#M40042</guid>
      <dc:creator>PeteJordan</dc:creator>
      <dc:date>2021-04-22T12:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Label Expression via Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1050090#M40054</link>
      <description>&lt;P&gt;Hi Pete.&amp;nbsp; Glad it worked out.&amp;nbsp; We can add those lines.&amp;nbsp; First though, here is a quick demo hopefully illustrating a few of the tougher tricks and functionality in that original code.&amp;nbsp; Run this using a Notebook in Pro.&amp;nbsp; Just cut and paste this into a cell and hit the Run arrow - see what prints.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;player = ['Steve Nash','Steph Curry', 'Kawhi']
stat = ['Assists','Threes','FG pctg']
num = [11,500,60]
apex_statistics = []
# zip basically runs a for loop with multiple lists simultaneously
for player, stat, num in zip(player, stat, num):
  # different formatting for fg pctg
  if stat in ['FG pctg']:
      num = '{}%'.format(num)
  # note this syntax (.format)is for more current Python versions.
  # Google / StackExchange from older posts will be similar but different
  # each {} will be populated by locationally matched item in ()  
  str = '{} master of {}:\n{} per year!'.format(player, stat, num)
  # add str to list one at a time each iteration of for loop
  apex_statistics.append(str)
# creates single string from the 3 strings in the list apex_statistics
full_str = '\n\n'.join(apex_statistics)
print(full_str)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;So to get the width string formatted, replace existing lines in if statement block for width with those shown below.&amp;nbsp; Note use either Option A or B (delete the other).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;  if [WIDTH] not in (None, "&amp;lt;NULL&amp;gt;", "0"):
    # option A basic
    width_str = 'Width: {}'.format([WIDTH])
    # option B - add units if you want too
    width_str = 'Width: {} Feet'.format([WIDTH])
    str_list.append(width_str)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;let me know if that works.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 14:32:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1050090#M40054</guid>
      <dc:creator>ZacharyUhlmann1</dc:creator>
      <dc:date>2021-04-22T14:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Label Expression via Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1050121#M40061</link>
      <description>&lt;P&gt;Great thanks again Zach.&amp;nbsp; I just have issues with the indentation a lot, so that's something I need to spend more time getting to know.&lt;/P&gt;&lt;P&gt;&amp;nbsp; I like that little tutorial you gave as well and will use that as a sample code for my own personal Python doc I'm making for myself so I can learn how things work better in Python.&lt;/P&gt;&lt;P&gt;&amp;nbsp; Thanks again&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 15:30:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/label-expression-via-python/m-p/1050121#M40061</guid>
      <dc:creator>PeteJordan</dc:creator>
      <dc:date>2021-04-22T15:30:22Z</dc:date>
    </item>
  </channel>
</rss>

