<?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:             How to count records returned by arcpy.da.SearchCursor in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791265#M1603</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am only interested in knowing it there are any records, not the number of records.&lt;/P&gt;&lt;P&gt;Could you please explain the other techniques.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 Jan 2019 12:41:18 GMT</pubDate>
    <dc:creator>JoseSanchez</dc:creator>
    <dc:date>2019-01-23T12:41:18Z</dc:date>
    <item>
      <title>How to count records returned by arcpy.da.SearchCursor</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791260#M1598</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to count records returned by a &lt;SPAN style="color: #6f008a; font-family: Consolas; font-size: small;"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #6f008a; font-family: Consolas; font-size: small;"&gt;da&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt;.SearchCursor&lt;/SPAN&gt;?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is how I am doing the count&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-family: Consolas; font-size: small;"&gt;# Initialize&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;count = 0&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; srcToday = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Consolas; font-size: small;"&gt;None&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Consolas; font-size: small;"&gt;with&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #6f008a; font-family: Consolas; font-size: small;"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #6f008a; font-family: Consolas; font-size: small;"&gt;da&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt;.SearchCursor(FeatureClass, fieldnames, whereClause) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Consolas; font-size: small;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; srcToday:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Consolas; font-size: small;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; rowToday &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Consolas; font-size: small;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; srcToday:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;count = count + 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: Consolas; font-size: small;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; count == 0:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;……&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jan 2019 19:04:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791260#M1598</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2019-01-22T19:04:52Z</dc:date>
    </item>
    <item>
      <title>Re:             How to count records returned by arcpy.da.SearchCursor</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791261#M1599</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;You can read the cursor with a list comprehension, like so:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;featureList &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;row&lt;SPAN class="punctuation 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;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;FeatureClass&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fieldnames&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; whereClause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;featureList&lt;SPAN class="punctuation token"&gt;)&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;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:04:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791261#M1599</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-12T09:04:19Z</dc:date>
    </item>
    <item>
      <title>Re:             How to count records returned by arcpy.da.SearchCursor</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791262#M1600</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it faster than:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: Consolas; font-size: small;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; rowToday &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: Consolas; font-size: small;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-family: Consolas; font-size: small;"&gt; srcToday:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;count = count + 1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jan 2019 20:06:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791262#M1600</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2019-01-22T20:06:40Z</dc:date>
    </item>
    <item>
      <title>Re:             How to count records returned by arcpy.da.SearchCursor</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791263#M1601</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Depending on how many records you have, probably not.&amp;nbsp; Search cursors are not the fastest things around.&amp;nbsp; What really helps speed them up is the 'where clause'.&amp;nbsp; That way it only 'hits' those records that meet the criteria.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jan 2019 20:24:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791263#M1601</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2019-01-22T20:24:20Z</dc:date>
    </item>
    <item>
      <title>Re:             How to count records returned by arcpy.da.SearchCursor</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791264#M1602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you need to count how many records result from a specific criteria, and not process those records, then Make Feature Layer and Get Count is the best.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you really want to use native Python, instead of geoprocessing tools, then most of the methods will all be similar in terms of performance because iterating through the entire cursor takes the same amount of time regardless of how you are counting the records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For me, the most Pythonic way would be to leverage Python built-in functions.&amp;nbsp; For example,&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;FeatureClass&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fieldnames&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; whereClause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; srcToday&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; sum&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; srcToday&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;/SPAN&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;Question, do you want to call how many records are in the cursor or whether there are any records?&amp;nbsp; If the latter, some techniques are much more efficient than others.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:04:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791264#M1602</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T09:04:21Z</dc:date>
    </item>
    <item>
      <title>Re:             How to count records returned by arcpy.da.SearchCursor</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791265#M1603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am only interested in knowing it there are any records, not the number of records.&lt;/P&gt;&lt;P&gt;Could you please explain the other techniques.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jan 2019 12:41:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791265#M1603</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2019-01-23T12:41:18Z</dc:date>
    </item>
    <item>
      <title>Re:             How to count records returned by arcpy.da.SearchCursor</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791266#M1604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since I am not sure what your code looks like before or after this point, I can't say whether this is the "best" overall approach.&amp;nbsp; Focusing only on the question of whether a cursor has any items/rows, Python's built-in &lt;A href="https://docs.python.org/3/library/functions.html#any" rel="nofollow noopener noreferrer" target="_blank"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;any&lt;/SPAN&gt;&lt;/A&gt; function is the most Pythonic both in terms of form and function.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; any&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;FeatureClass&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fieldnames&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; whereClause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; 
    &lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&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;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The above is checking for records, insert a &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;not&lt;/SPAN&gt; if you are interested in checking for no records.&amp;nbsp; What is great about &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;any&lt;/SPAN&gt;, beyond the semantic straightforwardness of using 'any' to check for any records, is that it also short-circuits and exits at the first &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;True&lt;/SPAN&gt; value.&amp;nbsp; This comes in especially handy when the iterable is very long, and looping through it would take time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:04:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-count-records-returned-by-arcpy-da/m-p/791266#M1604</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T09:04:24Z</dc:date>
    </item>
  </channel>
</rss>

