<?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:  use the field calculator to create a python code snippet to remove the last two characters from the values in field1 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312228#M24302</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;no problem &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Dec 2017 20:40:47 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2017-12-11T20:40:47Z</dc:date>
    <item>
      <title>use the field calculator to create a python code snippet to remove the last two characters from the values in field1</title>
      <link>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312222#M24296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am working on an assignment for my programming class (a class that I’m greatly struggling in) where I need to use the field calculator to create a python code snippet to remove the last two characters from the values in field 1. I know there are similar questions on this forum, yet I’m finding it hard to apply those suggestions to my problem. &amp;nbsp;Any guidance would be &lt;STRONG&gt;very&lt;/STRONG&gt; much appreciated.&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/390459_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2017 18:45:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312222#M24296</guid>
      <dc:creator>CourtneyWade</dc:creator>
      <dc:date>2017-12-11T18:45:21Z</dc:date>
    </item>
    <item>
      <title>Re:  use the field calculator to create a python code snippet to remove the last two characters from the values in field1</title>
      <link>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312223#M24297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In python, strings are iterables... in the field calculator use the python parser and it would be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;!YourFieldNameHere![:-2]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;of course you have to calculate this value into a new field&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;a &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'asdfasdfasxx'&lt;/SPAN&gt;

a&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="string token"&gt;'asdfasdfas'&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;P&gt;Now you didn't specify whether it is possible that the field would contain less than 2 characters.&amp;nbsp; This is a simple field calculation, so normally you would use a field calculation&lt;/P&gt;&lt;P&gt;and call it with&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;cal(!YourFieldNameHere!)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&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; &lt;SPAN class="token function"&gt;cal&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;""" replace the last two characters in a field"""&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; a&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Read the docs'&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 14:55:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312223#M24297</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T14:55:11Z</dc:date>
    </item>
    <item>
      <title>Re:  use the field calculator to create a python code snippet to remove the last two characters from the values in field1</title>
      <link>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312224#M24298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Courtney,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan's got you covered for using the codeblock parameter within &lt;A class="link-titled" href="http://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field.htm" title="http://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field.htm"&gt;Calculate Field&lt;/A&gt;. It's not clear to me if your assignment requires you to use that parameter. If not, you could just run:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;CalculateField_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Converted_Graphics"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"field1"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"!field1![:-2]"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"PYTHON_9.3"&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Keep at it. The GIS programming stuff gets easier with time, trial/error, and repetition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Micah&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2017 19:30:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312224#M24298</guid>
      <dc:creator>MicahBabinski</dc:creator>
      <dc:date>2017-12-11T19:30:32Z</dc:date>
    </item>
    <item>
      <title>Re:  use the field calculator to create a python code snippet to remove the last two characters from the values in field1</title>
      <link>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312225#M24299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, Dan! I got it!!! Thank you! I guess I didn't realize I needed to make a new field (makes perfect sense now). I was trying to 'correct' the existing field without any luck. You helped me one other time too....I appreciate you taking the time to answer my question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you have a great rest of your day!&lt;/P&gt;&lt;P&gt;Courtney&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2017 19:43:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312225#M24299</guid>
      <dc:creator>CourtneyWade</dc:creator>
      <dc:date>2017-12-11T19:43:37Z</dc:date>
    </item>
    <item>
      <title>Re:  use the field calculator to create a python code snippet to remove the last two characters from the values in field1</title>
      <link>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312226#M24300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Micah! Thank you for your suggestion. I was able to try your method on the next question and was able to make it work too.&amp;nbsp; It's is nice to know a few different ways to 'skin a cat'. My class is completely online so I'm kinda on my own here. I really appreciate you taking the time to answer my question.&lt;/P&gt;&lt;P&gt;Have a great day!&lt;/P&gt;&lt;P&gt;Courtney&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2017 19:50:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312226#M24300</guid>
      <dc:creator>CourtneyWade</dc:creator>
      <dc:date>2017-12-11T19:50:18Z</dc:date>
    </item>
    <item>
      <title>Re:  use the field calculator to create a python code snippet to remove the last two characters from the values in field1</title>
      <link>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312227#M24301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A little late in the conversation, but this website is well worth the bookmark:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://python-reference.readthedocs.io/en/latest/index.html" title="http://python-reference.readthedocs.io/en/latest/index.html"&gt;Python Reference (The Right Way) - DRAFT — Python Reference (The Right Way) 0.1 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2017 20:36:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312227#M24301</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2017-12-11T20:36:01Z</dc:date>
    </item>
    <item>
      <title>Re:  use the field calculator to create a python code snippet to remove the last two characters from the values in field1</title>
      <link>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312228#M24302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;no problem &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2017 20:40:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-the-field-calculator-to-create-a-python-code/m-p/312228#M24302</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-12-11T20:40:47Z</dc:date>
    </item>
  </channel>
</rss>

