<?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: How to slice a word in the label expression in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520781#M40830</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Error trapping is as much an art as it is a &amp;nbsp;science . &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Dec 2016 12:38:48 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2016-12-08T12:38:48Z</dc:date>
    <item>
      <title>How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520771#M40820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hallo,&lt;/P&gt;&lt;P&gt;I have a field with city names and I want to slice the name in the label expression to only the 1st character.&lt;/P&gt;&lt;P&gt;I want to do this in python. looking at the internet i have this but it is not working:&lt;/P&gt;&lt;P&gt;def Label ( [CityName] &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s = [CityName]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s1 = s[1:]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return s1&lt;/P&gt;&lt;P&gt;i am working with arcgis for desktop 10.3.1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;greetings Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Dec 2016 20:23:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520771#M40820</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2016-12-07T20:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520772#M40821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got this to work:&lt;/P&gt;&lt;P&gt;def wtf (instring):&lt;BR /&gt;&amp;nbsp; s= instring[:1]&amp;nbsp;&amp;nbsp; ####### Notice the position of the colon(:)&lt;BR /&gt;&amp;nbsp; return s&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Above is in the feild calculator, in a label expression be sure to choose python as the parser and check Advanced:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/278180_pastedImage_5.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Dec 2016 20:53:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520772#M40821</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2016-12-07T20:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520773#M40822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i stil got a string error&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/278395_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Dec 2016 06:37:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520773#M40822</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2016-12-08T06:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520774#M40823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could simplify the definition function even further:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; FindLabel &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;CITY_CODE&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;CITY_CODE&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:43:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520774#M40823</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2021-12-11T22:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520775#M40824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's probably due to an empty/Null attribute value, which could be returned as None. &amp;nbsp;Try this definition expression:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; FindLabel &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;CITY_CODE&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;CITY_CODE&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt; AttributeError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;pass&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:43:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520775#M40824</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2021-12-11T22:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520776#M40825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Your right there a NULL values and that was causing the error.&amp;nbsp; My code works if I&amp;nbsp;remove the NULL values but I need same on NULL.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;your code is giving me the same error.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Greetings Peter&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/278440_pastedImage_4.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;IMG class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/278447_pastedImage_5.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Dec 2016 07:54:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520776#M40825</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2016-12-08T07:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520777#M40826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's weird, because I tested the expression on a layer with Null values in the attribute filed and it worked. &amp;nbsp;How about adding a None type check in there?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; FindLabel &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;CityName&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;CityName&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;not&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;CityName&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt; AttributeError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;pass&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:43:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520777#M40826</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2021-12-11T22:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520778#M40827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is weird. i now got a other error&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/278448_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/278449_pastedImage_2.png" /&gt;&lt;/P&gt;&lt;P&gt;this is my field properstie&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-3 jive-image" src="https://community.esri.com/legacyfs/online/278456_pastedImage_3.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Dec 2016 08:13:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520778#M40827</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2016-12-08T08:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520779#M40828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have a left bracket in front of the CityName field in the if statement - I see I made the same error in my previous reply&amp;nbsp;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/silly.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Dec 2016 08:16:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520779#M40828</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2016-12-08T08:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520780#M40829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think it was my mistake I got a extra ( in the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;your code is working correctly. It is a more difficult code then I would think for such a simple task but I am really glad it works.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;def&lt;/SPAN&gt; FindLabel &lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt; &lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;[&lt;/SPAN&gt;CityName&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;]&lt;/SPAN&gt; &lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;:&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;try&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;if&lt;/SPAN&gt; &lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;[&lt;/SPAN&gt;CityName&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;]&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;is&lt;/SPAN&gt; &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit;"&gt;not&lt;/SPAN&gt; None&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;return&lt;/SPAN&gt; &lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;[&lt;/SPAN&gt;CityName&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;"&gt;1&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;]&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;except&lt;/SPAN&gt; AttributeError&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;pass&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:43:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520780#M40829</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2021-12-11T22:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to slice a word in the label expression</title>
      <link>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520781#M40830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Error trapping is as much an art as it is a &amp;nbsp;science . &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Dec 2016 12:38:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-slice-a-word-in-the-label-expression/m-p/520781#M40830</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2016-12-08T12:38:48Z</dc:date>
    </item>
  </channel>
</rss>

