<?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: Error Labelling Features Using Basic Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454652#M35733</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think it may be the way you have set up your if tests&lt;/P&gt;&lt;P&gt;1&amp;nbsp; what happens if el isn't greater than 0?​&amp;nbsp; is it supposed to return nt?&lt;/P&gt;&lt;P&gt;2 what happens if el % 0.5 isn't == 0 ? (put some spaces around operands by the way) it kind of goes nowhere right now and it may be getting confused, so put an else statement to finish the though on that comparison&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;if ( el % 0.5) == 0.0:&amp;nbsp; # shouldn't be testing for equality but within a tolerance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do something&lt;/P&gt;&lt;P&gt;else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do something else&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also are el and nt both strings? are they supposed to be returned as strings?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Mar 2015 04:01:28 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2015-03-09T04:01:28Z</dc:date>
    <item>
      <title>Error Labelling Features Using Basic Python</title>
      <link>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454651#M35732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using the below code to label contours of a small area. Due to laziness and simplicity, this polyline featureclass has both the contours AND pipes together, but they are easy to identify, as all pipes have a description in the notes field, and they have NULL in the elevation field, and visa versa.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Due to these fields being this way, I am hoping to setup a simple python script to label the contours with ELEVATION and pipes with NOTES attribute.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have my code working 99%, but as the contours are so close together I want to only show every 2nd line, so they are all contours with elevation / 0.5 with no remainder.&lt;/P&gt;&lt;P&gt;EG it would only return these: 150.00&amp;nbsp; &lt;SPAN style="text-decoration: line-through;"&gt;150.25&lt;/SPAN&gt;&amp;nbsp; 150.50&amp;nbsp; &lt;SPAN style="text-decoration: line-through;"&gt;150.75&lt;/SPAN&gt;&amp;nbsp; 151.00 &lt;SPAN style="text-decoration: line-through;"&gt;151.25&lt;/SPAN&gt;......&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code is giving me an error:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [ELEVATION], [NOTES] ):
&amp;nbsp; el = [ELEVATION]
&amp;nbsp; nt = [NOTES]
&amp;nbsp; if el &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (el%0.5)==0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return el # returns the elevation as it contains a value
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return nt # returns [NOTES] as label&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Error:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="2015-03-09_14-41-03_Weave_Alternate.mxd - ArcMap.jpg" class="image-1 jive-image" src="/legacyfs/online/71002_2015-03-09_14-41-03_Weave_Alternate.mxd - ArcMap.jpg" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can remove the line '&lt;SPAN style="color: #303030; font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif;"&gt;if (el%0.5)==0:' &lt;/SPAN&gt;and it works fine (just a bit messy). So i know this line contains the problem. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone tell me where I have gone wrong please?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:16:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454651#M35732</guid>
      <dc:creator>BenVan_Kesteren1</dc:creator>
      <dc:date>2021-12-11T20:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Error Labelling Features Using Basic Python</title>
      <link>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454652#M35733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think it may be the way you have set up your if tests&lt;/P&gt;&lt;P&gt;1&amp;nbsp; what happens if el isn't greater than 0?​&amp;nbsp; is it supposed to return nt?&lt;/P&gt;&lt;P&gt;2 what happens if el % 0.5 isn't == 0 ? (put some spaces around operands by the way) it kind of goes nowhere right now and it may be getting confused, so put an else statement to finish the though on that comparison&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;if ( el % 0.5) == 0.0:&amp;nbsp; # shouldn't be testing for equality but within a tolerance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do something&lt;/P&gt;&lt;P&gt;else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do something else&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also are el and nt both strings? are they supposed to be returned as strings?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2015 04:01:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454652#M35733</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-03-09T04:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Error Labelling Features Using Basic Python</title>
      <link>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454653#M35734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Cast your elevation value to a float and it should work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [ELEVATION] , [NOTES] ):
&amp;nbsp; el = [ELEVATION]
&amp;nbsp; nt = [NOTES]
&amp;nbsp; if el &amp;gt; 0:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (float(el)%0.5)==0: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return el
&amp;nbsp; else: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; return nt&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:16:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454653#M35734</guid>
      <dc:creator>OwenEarley</dc:creator>
      <dc:date>2021-12-11T20:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error Labelling Features Using Basic Python</title>
      <link>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454654#M35735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;el is a double, and notes is string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good point with the else, I forgot to put one!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2015 04:39:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454654#M35735</guid>
      <dc:creator>BenVan_Kesteren1</dc:creator>
      <dc:date>2015-03-09T04:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error Labelling Features Using Basic Python</title>
      <link>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454655#M35736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes this float() fixed the error. Combining your suggestion with an else: statement it now runs flawlessly...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [ELEVATION], [NOTES] ):
&amp;nbsp; el = [ELEVATION]
&amp;nbsp; nt = [NOTES]
&amp;nbsp; div = 1
&amp;nbsp; if float(el) &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (float(el)%div)==0.0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return el # returns the elevation as it contains a value
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:pass
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return [NOTES] # returns [NOTES] as label&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:17:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-labelling-features-using-basic-python/m-p/454655#M35736</guid>
      <dc:creator>BenVan_Kesteren1</dc:creator>
      <dc:date>2021-12-11T20:17:01Z</dc:date>
    </item>
  </channel>
</rss>

