<?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: Remove first 2 characters using if statement in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717008#M55568</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;is pseudo code&lt;BR /&gt;avalue (a row value in string format)&lt;BR /&gt;prefix = ["XY", "RR"]&lt;BR /&gt;if avalue[0:2] in prefix:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; avalue = avalue[2:]&lt;BR /&gt;print avalue&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;not really sure what to do here&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 12 Aug 2013 17:00:46 GMT</pubDate>
    <dc:creator>AmyKlug</dc:creator>
    <dc:date>2013-08-12T17:00:46Z</dc:date>
    <item>
      <title>Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717006#M55566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I would like to have this code remove and XY or RR (if they are the first 2 characters) in a field with values&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;XY2365541&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RR1247884&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;8965445&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;would be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2365541&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1247884&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;8965445&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Writing a query is giving me trouble. I was trying this code with a search cursor, getvalue and if elif statement...but no luck&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy Feature_Class_Name = arcpy.GetParameterAsText(0) Output_Features = arcpy.GetParameterAsText(1) arcpy.env.workspace = r"H:/TestMDB.gdb/XY_1"&amp;nbsp; cursor = arcpy.da.UpdateCursor(Feature_Class_Name, ["NM"]) for row in cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow([row[0][2:]]) del fc&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 21:54:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717006#M55566</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2013-08-09T21:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717007#M55567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;is pseudo code&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;avalue (a row value in string format)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;prefix = ["XY", "RR"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if avalue[0:2] in prefix:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; avalue = avalue[2:]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print avalue&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 22:10:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717007#M55567</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-08-09T22:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717008#M55568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;is pseudo code&lt;BR /&gt;avalue (a row value in string format)&lt;BR /&gt;prefix = ["XY", "RR"]&lt;BR /&gt;if avalue[0:2] in prefix:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; avalue = avalue[2:]&lt;BR /&gt;print avalue&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;not really sure what to do here&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 17:00:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717008#M55568</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2013-08-12T17:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717009#M55569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dan said you "here's your pseudocode", so you have to test something out -- this line is wrong:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;cursor.updateRow([row[0][2:]])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...believe you have to set the row field val 1st then update the row...as in something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;row[0] = row[0][2:]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cursor.updateRow(row)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try that substitution...actually, I think you specified you wanted to test for the 1st 2 char, then substitute something else - so you'll need an 'if' statement, plenty of examples in the web help.&amp;nbsp; Make a copy of your fc, and start experimenting, following the above for starters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 17:08:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717009#M55569</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-08-12T17:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717010#M55570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Dan said you "here's your pseudocode", so you have to test something out -- this line is wrong:&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;cursor.updateRow([row[0][2:]])&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;...believe you have to set the row field val 1st then update the row...as in something like:&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;row[0] = row[0][2:]&amp;nbsp; &lt;BR /&gt;cursor.updateRow(row)&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;Try that substitution...actually, I think you specified you wanted to test for the 1st 2 char, then substitute something else - so you'll need an 'if' statement, plenty of examples in the web help. Make a copy of your fc, and start experimenting, following the above for starters.&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;Enjoy,&amp;nbsp; &lt;BR /&gt;Wayne&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will be more specific......&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;is pseudo code&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;avalue (a row value in string format)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;prefix = ["XY", "RR"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;if avalue[0:2] in prefix&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;avalue = avalue[2:]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print avalue&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I read this as.......if row[0:2] in ["XY", "RR].........this makes no sense to me. Row[0:2] is a row value such as XY885442554 and nothing I have tried recognizes ["XY, "RR"]. Do I need to also use a search cursor?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 19:27:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717010#M55570</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2013-08-12T19:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717011#M55571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Within a cursor of some form (insert possibly in your case), if the first two characters ( [0:2] ) are "XY" or "RR" are found within the offending list ["XY", "RR"], substitute/update your field/row with the value with those values removed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is hard to debug someone else's code unless you have field calculator syntax that works before you move on to automating the process to include multiple cases.&amp;nbsp; Try to simply the operation by performing single steps at a time (eg.&amp;nbsp; strip off "XY" if it is contained within a field) then move onto the next selection finding fields that begin with "RR" and stripping those off.&amp;nbsp; If this is a one-off deal you are done...if this is daily, then generate a field calculator expression which covers all cases.&amp;nbsp;&amp;nbsp; I often find the former faster than the latter and I have been coding for years.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 19:42:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717011#M55571</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-08-12T19:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717012#M55572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, maybe the 'stumbling block' here is the isolation of text to trim, or at least selecting those for some kind of conditional 'slicing' or text formatting, whatever -- so I have found the best way to grow more accustomed to how Python handles string handling is to test something interactively, say in IDLE or ArcMap's python window.&amp;nbsp; You can even test expressions in the field calculator - as long as you have saved a copy of your data, you can practice, no matter really if it succeeds/fails or even crashes/freezes ArcMap, think we've all done that...restart and try again.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Having said that, check out this behavior using IDLE:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; bunchOfValues = ('XY885442554', 'TY3485694873', 'RR473892711')
&amp;gt;&amp;gt;&amp;gt; print bunchOfValues
('XY885442554', 'TY3485694873', 'RR473892711')
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; for eachValue in bunchOfValues:
 print eachValue

 
XY885442554
TY3485694873
RR473892711
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; for eachValue in bunchOfValues:
 if eachValue[0:2] in ['XY', 'RR']:
&amp;nbsp; print eachValue[2:]
 else:
&amp;nbsp; print eachValue

&amp;nbsp; 
885442554
TY3485694873
473892711
&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...still want more, see this, the skinny:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://stackoverflow.com/questions/509211/the-python-slice-notation" rel="nofollow noopener noreferrer" target="_blank"&gt;http://stackoverflow.com/questions/509211/the-python-slice-notation&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:42:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717012#M55572</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-12T06:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717013#M55573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Dan and Wayne.....that really helped. Here is the final code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; fc = r"H:/Test.gdb/NameTest"
&amp;gt;&amp;gt;&amp;gt; cursor = arcpy.da.UpdateCursor(fc, ["NM"])
&amp;gt;&amp;gt;&amp;gt; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = row[0]
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[:2] == "XY":&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow([row[2:]])&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif row[:2] == "RR":&amp;nbsp;&amp;nbsp;&amp;nbsp; 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow([row[2:]])
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Name field is alread up-to-date"
&amp;gt;&amp;gt;&amp;gt;&amp;gt; del fc, cursor
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:42:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717013#M55573</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2021-12-12T06:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717014#M55574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To emphasize the useage of the "in" list operand consider the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; bunchOfValues = ['XY885442554', 'TY3485694873', 'RR473892711']
&amp;gt;&amp;gt;&amp;gt; for aValue in bunchOfValues:
...&amp;nbsp; if aValue[:2] in ['XY', 'RR']:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print aValue[2:]
...&amp;nbsp; else:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print aValue
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
885442554
TY3485694873
473892711&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;particularly useful to avoid extensive if, elif, else statements&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:42:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717014#M55574</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T06:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717015#M55575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;To emphasize the useage of the "in" list operand consider the following:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; bunchOfValues = ['XY885442554', 'TY3485694873', 'RR473892711']
&amp;gt;&amp;gt;&amp;gt; for aValue in bunchOfValues:
...&amp;nbsp; if aValue[:2] in ['XY', 'RR']:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print aValue[2:]
...&amp;nbsp; else:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print aValue
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
885442554
TY3485694873
473892711&lt;/PRE&gt;&lt;BR /&gt;particularly useful to avoid extensive if, elif, else statements&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;True! Here is the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; fc = r"H:/Test.gdb/XY_1_1"
&amp;gt;&amp;gt;&amp;gt; cursor = arcpy.da.UpdateCursor(fc, ["NM"])
&amp;gt;&amp;gt;&amp;gt; prefix = ["XY", "RR"]
&amp;gt;&amp;gt;&amp;gt; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = row[0]
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[:2] in prefix: 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow([row[2:]])
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Name is up-to-date"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:42:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717015#M55575</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2021-12-12T06:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717016#M55576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That's great Amy!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And just to go a little further because I think I steered you a wee bit wrong in post 4, I said this was 'wrong' but now I don't think so (except you needed the 'if' statement of course):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;cursor.updateRow([row[0][2:]])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually, I think your code could be shortened to almost what you had originally, see the following, if I can get the formatting preserved from your last post:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; fc = r"H:/Test.gdb/XY_1_1"
&amp;gt;&amp;gt;&amp;gt; cursor = arcpy.da.UpdateCursor(fc, ["NM"])
&amp;gt;&amp;gt;&amp;gt; prefix = ["XY", "RR"]
&amp;gt;&amp;gt;&amp;gt; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0][:2] in prefix: 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow([row[0][2:]])
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Name is up-to-date"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...where 'row[0]' is your field object from the list that was previously specified as row = row[0].&amp;nbsp; Just this line was removed....I didn't test this, but pretty certain it works.&amp;nbsp; I'm just saying you should be able to do it either way.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that makes sense....I'm more accustomed 'seeing' it the other way and actually you should probably make it however is most readable to you (or your workmates, if they see the code).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That's very interesting - and the code I posted may not work!&amp;nbsp; (That's what you get when you post code you have not tested, lol!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the Method Overview for the da (data access) module for the UpdateCursor, I only see 'updateRow(row)' where row must be the row object of the cursor -- so if the above code does not work (sorry) or if having trouble, you could try this (I cannot test this da update cursor method at the moment):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; fc = r"H:/Test.gdb/XY_1_1"
&amp;gt;&amp;gt;&amp;gt; cursor = arcpy.da.UpdateCursor(fc, ["NM"])
&amp;gt;&amp;gt;&amp;gt; prefix = ["XY", "RR"]
&amp;gt;&amp;gt;&amp;gt; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0][:2] in prefix: 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = row[0][2:]
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Name is up-to-date"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:42:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717016#M55576</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-12T06:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Remove first 2 characters using if statement</title>
      <link>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717017#M55577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you just want to extract the digits and ignore everything else, why not make it simple:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; with arcpy.da.UpdateCursor("Stream_points",['TEST']) as rows: ...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows: ...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v = row[0] ...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = ''.join(i for i in v if i.isdigit()) ...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row) ...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will yield:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2365541&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1247884&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;8965445&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: I should clarify that this removes ALL text and leaves ONLY the digits.&amp;nbsp; If you want to keep other prefixes use Dan or Wayne's method.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 19:29:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-first-2-characters-using-if-statement/m-p/717017#M55577</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-08-13T19:29:42Z</dc:date>
    </item>
  </channel>
</rss>

