<?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: Why is this code producing an infinite loop in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134893#M10590</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The Mark as Helpful option is hidden in the Actions drop down menu.&amp;nbsp; That is even less obvious than the old forum's buttons on the right side of each post that all new users overlooked.&amp;nbsp; This option should be more obviously exposed if it is the new basis of MVP rankings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are Likes considered?&amp;nbsp; Likes are the only thing I see anyone do consistently here and the only thing I could easily see that I could apply to each post.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Sep 2014 19:40:45 GMT</pubDate>
    <dc:creator>RichardFairhurst</dc:creator>
    <dc:date>2014-09-11T19:40:45Z</dc:date>
    <item>
      <title>Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134884#M10581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have tried this code and it is producing an infinite loop that repeatedly prints "0 Records Selected".&amp;nbsp; I know that the query is resulting in 0 records being selected.&amp;nbsp; Why is the value returned from the GetCount_management function that reports as 0 considered be greater than or equal to 1?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14104566213729115" jivemacro_uid="_14104566213729115" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;import os&lt;/P&gt;
&lt;P&gt;from time import strftime&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;updateFC = r"C:\Users\RFAIRHUR\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Trans Connection to SQL Server.sde\GDB_TRANS.TRANS.TRANSPORTATION_MAINT\CENTERLINE"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Make Feature Layer: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;arcpy.MakeFeatureLayer_management(updateFC, "CENTERLINE_Layer")&lt;/P&gt;
&lt;P&gt;arcpy.SelectLayerByAttribute_management("CENTERLINE_Layer", "NEW_SELECTION", "OBJECTID = -1")&lt;/P&gt;
&lt;P&gt;records = arcpy.GetCount_management("CENTERLINE_Layer")&lt;/P&gt;
&lt;P&gt;while (records &amp;gt;= 1):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(arcpy.GetCount_management("CENTERLINE_Layer")) + " Records Selected: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("CENTERLINE_Layer", "NEW_SELECTION", "OBJECTID = -1")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; records = arcpy.GetCount_management("CENTERLINE_Layer")&lt;/P&gt;
&lt;P&gt;print "Finished All Records: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This alteration to the code works without producing an infinite loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14104570674133199" jivemacro_uid="_14104570674133199" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;import os&lt;/P&gt;
&lt;P&gt;from time import strftime&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;records = 0&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;while (records &amp;gt;= 1):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; print str(records) + " Records Selected: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;##&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(arcpy.GetCount_management("CENTERLINE_Layer")) + " Records Selected: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;##&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("CENTERLINE_Layer", "NEW_SELECTION", "OBJECTID = -1")&lt;/P&gt;
&lt;P&gt;##&amp;nbsp;&amp;nbsp;&amp;nbsp; records = arcpy.GetCount_management("CENTERLINE_Layer")&lt;/P&gt;
&lt;P&gt;print "Finished All Records: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 18:17:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134884#M10581</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-09-11T18:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134885#M10582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin: 0 0 1em;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;arcpy.GetCount_management&lt;/SPAN&gt; returns a&lt;/SPAN&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt; &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Result/018z00000046000000/"&gt;Result&lt;/A&gt; object and you have to cast it as int to check against it:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;int(arcpy.GetCount_management("&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;CENTERLINE_Layer&lt;/SPAN&gt;").getOutput(0))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 18:26:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134885#M10582</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2014-09-11T18:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134886#M10583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;GetCount returns a result object, not an integer count of the number of features selected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;see &lt;A href="http://gis.stackexchange.com/questions/55246/cast-arcpy-result-as-an-integer-instead-arcpy-getcount-management" title="http://gis.stackexchange.com/questions/55246/cast-arcpy-result-as-an-integer-instead-arcpy-getcount-management"&gt;python - Cast arcpy result as an integer instead (arcpy.GetCount_management) - Geographic Information Systems Stack Exch…&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 18:42:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134886#M10583</guid>
      <dc:creator>ThomasTri</dc:creator>
      <dc:date>2014-09-11T18:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134887#M10584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let me amplify a bit because this is an important thread, and a FAQ for arcpy users!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This was a change made with the geoprocessor at 9.3. Before then, tools always returned strings. Now, you get a &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018z00000046000000"&gt;result object&lt;/A&gt; out from tools. This result object can contain one or several results, usually as unicode strings. Most tools have only one result (say, a path or a count) so you can easily get the string representation if you need it using the str() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14104612760999348 jive_text_macro" jivemacro_uid="_14104612760999348" modifiedtitle="true"&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.GetCount_management("centroid_points.shp")&lt;/P&gt;
&lt;P&gt;&amp;lt;Result '231'&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.GetCount_management("centroid_points.shp").getOutput(0)&lt;/P&gt;
&lt;P&gt;u'231'&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; str(arcpy.GetCount_management("centroid_points.shp"))&lt;/P&gt;
&lt;P&gt;'231'&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a function that makes getting that count a little easier:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14104615572021880 jive_text_macro" jivemacro_uid="_14104615572021880"&gt;
&lt;P&gt;def GetCount(input):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """GetCount in one step (like 9.2 GetCount tool - except returns int)"""&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return int(arcpy.GetCount(input).GetOutput(0))&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 18:53:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134887#M10584</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-09-11T18:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134888#M10585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Richard did this post not answer your question?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 18:57:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134888#M10585</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2014-09-11T18:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134889#M10586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. I had read that many months ago, but forgotten.&amp;nbsp; I did consult the help for Get Count when I wrote the code, but obviously I only glanced through it and overlooked that it was returning an object and not a number.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 18:58:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134889#M10586</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-09-11T18:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134890#M10587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I switched the correct answer to yours, although I would say all of the answers I have seen are correct.&amp;nbsp; It only lets me mark one, but since yours included the code I can paste into my script and was posted first, I switched the answer to yours.&amp;nbsp; (I gave all of them Like points).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 19:01:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134890#M10587</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-09-11T19:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134891#M10588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Richard&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 19:04:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134891#M10588</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2014-09-11T19:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134892#M10589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; background-color: #f3f3f3;"&gt;It only lets me mark one&lt;/SPAN&gt; [as correct]&lt;/P&gt;
&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/4811"&gt;Richard Fairhurst&lt;/A&gt;‌ I realize this is is adding some meta to the thread -- but you can provide credit to others that add to the content of the thread by marking responses helpful and this will further up-rank the thread in searches. Just a thought!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 19:32:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134892#M10589</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-09-11T19:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why is this code producing an infinite loop</title>
      <link>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134893#M10590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The Mark as Helpful option is hidden in the Actions drop down menu.&amp;nbsp; That is even less obvious than the old forum's buttons on the right side of each post that all new users overlooked.&amp;nbsp; This option should be more obviously exposed if it is the new basis of MVP rankings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are Likes considered?&amp;nbsp; Likes are the only thing I see anyone do consistently here and the only thing I could easily see that I could apply to each post.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 19:40:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-this-code-producing-an-infinite-loop/m-p/134893#M10590</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-09-11T19:40:45Z</dc:date>
    </item>
  </channel>
</rss>

