<?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: Help with dynamic label python code in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-with-dynamic-label-python-code/m-p/90914#M7097</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a rewrite of your FindLabel function.&amp;nbsp; It uses Blake's suggestions; there are a number of ways to do the same thing in Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ([BLM], [BR], [Private], [SITLA]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; label_str = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; if [BLM] : label_str += "BLM: {} acres\n".format([BLM])
&amp;nbsp;&amp;nbsp;&amp;nbsp; if [BR] : label_str += "BR: {} acres\n".format([BR])
&amp;nbsp;&amp;nbsp;&amp;nbsp; if [Private] : label_str += "Private: {} acres\n".format([Private])
&amp;nbsp;&amp;nbsp;&amp;nbsp; if [SITLA] : label_str += "SITLA: {} acres\n".format([SITLA])
&amp;nbsp;&amp;nbsp;&amp;nbsp; return label_str.strip()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 23:29:02 GMT</pubDate>
    <dc:creator>RandyBurton</dc:creator>
    <dc:date>2021-12-10T23:29:02Z</dc:date>
    <item>
      <title>Help with dynamic label python code</title>
      <link>https://community.esri.com/t5/python-questions/help-with-dynamic-label-python-code/m-p/90911#M7094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello friend. I am pretty basic with Python and have a question about writing out a label.&lt;/P&gt;&lt;P&gt;I have an attribute table with multiple fields with floating point acreages in the fields. Not all of the fields necessarily have to contain a value; most of them are &amp;lt;Null&amp;gt;.&lt;/P&gt;&lt;P&gt;I am trying to build a label expression for a data driven map book that looks at the fields, and if it it has a value, add it to the label with leading text, then look at the next field. So far, I have using the IF statement and once the statement is true, it stops and does not search for the other true values. &lt;/P&gt;&lt;P&gt;Is there any If-and statement that I can use?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;P&gt;Function FindLabel ( [BLM] , [BR] , [Private] , [SITLA] )&lt;/P&gt;&lt;P&gt;&amp;nbsp; if ( ( [BLM] ) &amp;gt; 0) then&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FindLabel = "BLM: " + [BLM] + " acres"&lt;/P&gt;&lt;P&gt;&amp;nbsp; elseif&amp;nbsp; ( ( [BR] ) &amp;gt; 0) then&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FindLabel = "BR: " + [BR] + " acres"&lt;/P&gt;&lt;P&gt;&amp;nbsp; elseif&amp;nbsp; ( ( [Private] ) &amp;gt; 0) then&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FindLabel = "Private: " + [Private] + " acres"&lt;/P&gt;&lt;P&gt;&amp;nbsp; elseif&amp;nbsp; ( ( [SITLA] ) &amp;gt; 0) then&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FindLabel = "SITLA: " + [SITLA] + " acres"&lt;/P&gt;&lt;P&gt;&amp;nbsp; end if &lt;/P&gt;&lt;P&gt;End Function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming that there were acreages in each of the fields except [BR], I would want the label to read&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BLM: 44.59 acres&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Private: 89.01 acres&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SITLA: 1.89 acres&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jul 2016 20:36:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-dynamic-label-python-code/m-p/90911#M7094</guid>
      <dc:creator>SeanEdwards</dc:creator>
      <dc:date>2016-07-14T20:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Help with dynamic label python code</title>
      <link>https://community.esri.com/t5/python-questions/help-with-dynamic-label-python-code/m-p/90912#M7095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are wanting to print the possible combinations, you wouldn't use an elseif.&amp;nbsp; Try something like this (but adapted for FindLabel):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;BLM = 5.5
BR = None
PVT =&amp;nbsp; 6.5
SITLA = 7.5
label_str = ""

if BLM : label_str = "BLM: " + str(BLM) + " acres\n"
if BR : label_str = label_str + "BR: " + str(BR) + " acres\n"
if PVT : label_str = label_str + "PVT: " + str(PVT) + " acres\n"
if SITLA : label_str = label_str + "SITLA: " + str(SITLA) + " acres\n"

find_label = label_str
print find_label&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:28:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-dynamic-label-python-code/m-p/90912#M7095</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-10T23:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Help with dynamic label python code</title>
      <link>https://community.esri.com/t5/python-questions/help-with-dynamic-label-python-code/m-p/90913#M7096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you use &lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;A href="https://docs.python.org/2/library/stdtypes.html#str.format"&gt;str.format()&lt;/A&gt;&lt;/SPAN&gt; it will automatically make the non-string values text instead of having to do it manually. You can also use &lt;SPAN style="font-family: 'courier new', courier;"&gt;+=&lt;/SPAN&gt; to add to an existing value.&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14685353394241035 jive_text_macro" data-renderedposition="35_8_1186_16" jivemacro_uid="_14685353394241035"&gt;label_str += "BR: {} acres\n".format(BR)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jul 2016 22:29:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-dynamic-label-python-code/m-p/90913#M7096</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2016-07-14T22:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with dynamic label python code</title>
      <link>https://community.esri.com/t5/python-questions/help-with-dynamic-label-python-code/m-p/90914#M7097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a rewrite of your FindLabel function.&amp;nbsp; It uses Blake's suggestions; there are a number of ways to do the same thing in Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ([BLM], [BR], [Private], [SITLA]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; label_str = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; if [BLM] : label_str += "BLM: {} acres\n".format([BLM])
&amp;nbsp;&amp;nbsp;&amp;nbsp; if [BR] : label_str += "BR: {} acres\n".format([BR])
&amp;nbsp;&amp;nbsp;&amp;nbsp; if [Private] : label_str += "Private: {} acres\n".format([Private])
&amp;nbsp;&amp;nbsp;&amp;nbsp; if [SITLA] : label_str += "SITLA: {} acres\n".format([SITLA])
&amp;nbsp;&amp;nbsp;&amp;nbsp; return label_str.strip()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:29:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-dynamic-label-python-code/m-p/90914#M7097</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-10T23:29:02Z</dc:date>
    </item>
  </channel>
</rss>

