<?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: Extract string in field calculator using python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315292#M24506</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd use a slightly different, more "pythonesque" approach using a list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; str = "North: 4479928.51 East: 290941.79"
&amp;gt;&amp;gt;&amp;gt; spam = str.split()
&amp;gt;&amp;gt;&amp;gt; spam
['North:', '4479928.51', 'East:', '290941.79']
&amp;gt;&amp;gt;&amp;gt; x,y = float(spam[1]),float(spam[3])
&amp;gt;&amp;gt;&amp;gt; x
4479928.5099999998
&amp;gt;&amp;gt;&amp;gt; y
290941.78999999998
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 15:00:18 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2021-12-11T15:00:18Z</dc:date>
    <item>
      <title>Extract string in field calculator using python</title>
      <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315289#M24503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd like to use python in the field calculator to extract a string.&amp;nbsp; Basically the UTM North and East coordinates are in the same field and I'd like to parse them out.&amp;nbsp; An example of a field value is "North: 4479928.51 East: 290941.79".&amp;nbsp; When I run this very simple function in python, it works fine:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; def utmn(inValue):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; utmn_start = inValue.find(":") + 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; utmn_stop = inValue.find("East") -1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; return inValue[utmn_start:utmn_stop]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; utmn(field)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'4479928.51'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, when I try to run it in the ArcGIS field calculator, i get an error message that the row contains a bad value.&amp;nbsp; None of the rows are null or contain text that is not in this format.&amp;nbsp; Here's what I put in the field calculator.&amp;nbsp; MERIDIAN_NAME_TEXT is the name of the field from which I am extracting the string.&amp;nbsp; UTM_North is the name of the input field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pre-Logic Script Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def utmn(inValue):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; utmn_start = inValue.find(":") + 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; utmn_stop = inValue.find("East") -1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; return inValue[utmn_start:utmn_stop]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;UTM_North =&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;utmn(!MERIDIAN_NAME_TEXT!)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2011 15:15:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315289#M24503</guid>
      <dc:creator>StephanieSnider</dc:creator>
      <dc:date>2011-12-02T15:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string in field calculator using python</title>
      <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315290#M24504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would honestly just calculate with VB&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for the Easting Field i would use&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Right([Field], 9)&amp;nbsp; {[Field] is the name of the field, 9 is the number of spaces you want to include for the easting coordinate}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and for the Northing Field I'd do a find and replace for North: and for East:&amp;nbsp; Replacing it with nothing and leaving the Coordinate&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2011 15:37:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315290#M24504</guid>
      <dc:creator>AnthonyTimpson2</dc:creator>
      <dc:date>2011-12-02T15:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string in field calculator using python</title>
      <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315291#M24505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The coordinate value length is inconsistent.&amp;nbsp; That's why I do the find to determine the stop and start index for extraction.&amp;nbsp; I'd prefer to do this in python as I plan to do future field calculations using python.&amp;nbsp; But thanks for your suggestion.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2011 15:53:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315291#M24505</guid>
      <dc:creator>StephanieSnider</dc:creator>
      <dc:date>2011-12-02T15:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string in field calculator using python</title>
      <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315292#M24506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd use a slightly different, more "pythonesque" approach using a list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; str = "North: 4479928.51 East: 290941.79"
&amp;gt;&amp;gt;&amp;gt; spam = str.split()
&amp;gt;&amp;gt;&amp;gt; spam
['North:', '4479928.51', 'East:', '290941.79']
&amp;gt;&amp;gt;&amp;gt; x,y = float(spam[1]),float(spam[3])
&amp;gt;&amp;gt;&amp;gt; x
4479928.5099999998
&amp;gt;&amp;gt;&amp;gt; y
290941.78999999998
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:00:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315292#M24506</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T15:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string in field calculator using python</title>
      <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315293#M24507</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That works Curtis, thanks.&amp;nbsp; However, I'd still like to know why my definition worked in python IDLE but not the field calculator.&amp;nbsp; I'm trying to improve my skills and just don't see why my definition would have failed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2011 18:12:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315293#M24507</guid>
      <dc:creator>StephanieSnider</dc:creator>
      <dc:date>2011-12-02T18:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string in field calculator using python</title>
      <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315294#M24508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;(I) don't see why my definition would have failed.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you try this? Since your input field is text value you may need to put it in quotes. I believe the actual value gets substituted in before the Python expression is interpreted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;UTM_North =
utmn("!MERIDIAN_NAME_TEXT!") &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:00:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315294#M24508</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T15:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string in field calculator using python</title>
      <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315295#M24509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No, that didn't work either.&amp;nbsp; Error 539 - error running expression.&amp;nbsp; I've had this issue before where a function will work in python and not ArcGIS.&amp;nbsp; I keep thinking there is some small thing I'm not doing, that ArcGIS requires and python doesn't.&amp;nbsp; Oh well.&amp;nbsp; Thanks for your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2011 19:37:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315295#M24509</guid>
      <dc:creator>StephanieSnider</dc:creator>
      <dc:date>2011-12-02T19:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string in field calculator using python</title>
      <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315296#M24510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I ran your code and it worked. Check the field size and type of UTM_North. If the field is too small you'll get the error you mention. I assume you'd also get an error if you were trying to write into a FLOAT field since your function is returning a string. If that's the case then try converting with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;float(utmn(!MERIDIAN_NAME_TEXT!))&lt;/PRE&gt;&lt;SPAN&gt; OR &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;return float(inValue[utmn_start:utmn_stop])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also note, I think your stop value with -1 makes the last character the space before "East" so maybe use -2.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And I agree with Curtis regarding his suggested code for this particular task.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Dec 2011 02:57:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315296#M24510</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2011-12-03T02:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract string in field calculator using python</title>
      <link>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315297#M24511</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That all makes sense.&amp;nbsp; I had the field size about 4 characters larger than I thought it needed to be, but perhaps there is a value in there that is bigger.&amp;nbsp; Thanks for your advice &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; I'll give it a try.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Dec 2011 15:28:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-string-in-field-calculator-using-python/m-p/315297#M24511</guid>
      <dc:creator>StephanieSnider</dc:creator>
      <dc:date>2011-12-03T15:28:31Z</dc:date>
    </item>
  </channel>
</rss>

