<?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: Python expression failing to execute in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-expression-failing-to-execute/m-p/463978#M15602</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check your conditions … if sp = 5 it should be in the range 1-6&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;sp &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;5&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="operator token"&gt;&amp;lt;&lt;/SPAN&gt; sp &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# ---- good&lt;/SPAN&gt;
&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;

&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; sp &lt;SPAN class="operator token"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# ---- not correct&lt;/SPAN&gt;
&lt;SPAN class="token boolean"&gt;False&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 20:36:40 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2021-12-11T20:36:40Z</dc:date>
    <item>
      <title>Python expression failing to execute</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-expression-failing-to-execute/m-p/463976#M15600</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to process a Python If statement using Field Calculator. What I want is to calculate the value of a string field by evaluating the values recorded in a double field. Essentially, calculating travel mode based on speed ranges (0 = stationary, 1-6 = walk, 7-19 = cycling, 20+ = driving).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, my expression fails to process in ArcPro. Below is the expression in full, along with the output I received:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/452531_Capture.PNG" /&gt;&lt;IMG alt="" class="image-2 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/452532_Untitled.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Jul 2019 18:08:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-expression-failing-to-execute/m-p/463976#M15600</guid>
      <dc:creator>MalcolmLittle</dc:creator>
      <dc:date>2019-07-07T18:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python expression failing to execute</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-expression-failing-to-execute/m-p/463977#M15601</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/12727" target="_blank"&gt;Malcolm Little&lt;/A&gt;&lt;/P&gt;&lt;P&gt;‌&lt;/P&gt;&lt;P&gt;First is you are getting a lock acquisition error, do you have multiple copies open of the table you are attempting to update?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second&amp;nbsp;use something like TravelMode =&amp;nbsp;&lt;STRONG&gt;speedType&lt;/STRONG&gt; (!Speed!) .&amp;nbsp; "Type" is a&amp;nbsp;function in Python and should not be used as a def name.&amp;nbsp; It will work, but is poor practice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Third&amp;nbsp;for the Code Block, the way you have it coded "sp" is not assigned a value you have assigned the speed to "modey" when you called your function.&amp;nbsp; "sp" is only defined as a global and never set.&amp;nbsp; Your logic also does not&amp;nbsp;handle NULL values or negative values that could be in your data.&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;speedType&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;sp&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; sp &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"stationary"&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; sp &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"walk"&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;7&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; sp &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;19&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"cycle"&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"drive"&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;/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 20:36:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-expression-failing-to-execute/m-p/463977#M15601</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2021-12-11T20:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python expression failing to execute</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-expression-failing-to-execute/m-p/463978#M15602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check your conditions … if sp = 5 it should be in the range 1-6&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;sp &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;5&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="operator token"&gt;&amp;lt;&lt;/SPAN&gt; sp &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# ---- good&lt;/SPAN&gt;
&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;

&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; sp &lt;SPAN class="operator token"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# ---- not correct&lt;/SPAN&gt;
&lt;SPAN class="token boolean"&gt;False&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 20:36:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-expression-failing-to-execute/m-p/463978#M15602</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T20:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python expression failing to execute</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-expression-failing-to-execute/m-p/463979#M15603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/3116"&gt;Dan,&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for that catch.&amp;nbsp; I was looking at the code and not the logic in my responce.&amp;nbsp; Adjusted my reply as well...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Jul 2019 18:46:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-expression-failing-to-execute/m-p/463979#M15603</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2019-07-07T18:46:28Z</dc:date>
    </item>
  </channel>
</rss>

