<?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 get number records returned by 2nd cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-number-records-returned-by-2nd-cursor/m-p/630648#M49098</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I want to get the number of records in&amp;nbsp; table1 returned first by an UpdateCursor and then in table2 get the number of records returned by a SearchCursor. My code uses GetCount_management and works fine getting the number of rows returned for the first table. For the&amp;nbsp; second table,&amp;nbsp; I try this same process, but I am not getting the number of selected records, I get the TOTAL number of records in the table which I dont care about.&amp;nbsp; I know I've seen this happen before but can't remember why it's happening. Thanks in advance for the help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.UpdateCursor(inPtMeasureTbl,("STREAM_CODE","SPECSTR","TYPE","MEAS","PROB"), "TYPE = 'MIDSP' " ) as mainCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = arcpy.GetCount_management(inPtMeasureTbl)
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = int(result.getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print count #this works fine
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for curRec in mainCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print "Working on AWC_CODE: %s&amp;nbsp; Specstr: %s&amp;nbsp; Meas: %f" % (curRec[0], curRec[1], curRec[3])&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Compare to # of line events occurring at this spot
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; srchExpr = "STREAM_CODE='%s' and F_MEAS &amp;lt;= %f and T_MEAS &amp;gt;= %f" % (curRec[0], curRec[3],curRec[3] )
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(inEventTbl,("STREAM_CODE","SPECLS","F_MEAS","T_MEAS"), srchExpr) as lkupCursor:&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numLineEvents = int(arcpy.GetCount_management(inEventTbl).getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print numLineEvents #THIS NUMBER IS THE TOTAL WHICH IS WRONG

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for curEventTbl in lkupCursor:
&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;&amp;nbsp; print "Found event: %s&amp;nbsp; Specstr: %s&amp;nbsp; Measures: %f , %f" % (curEventTbl[0],curEventTbl[1], curEventTbl[2], curEventTbl[3])&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 02:49:50 GMT</pubDate>
    <dc:creator>SkipRepetto</dc:creator>
    <dc:date>2021-12-12T02:49:50Z</dc:date>
    <item>
      <title>get number records returned by 2nd cursor</title>
      <link>https://community.esri.com/t5/python-questions/get-number-records-returned-by-2nd-cursor/m-p/630648#M49098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I want to get the number of records in&amp;nbsp; table1 returned first by an UpdateCursor and then in table2 get the number of records returned by a SearchCursor. My code uses GetCount_management and works fine getting the number of rows returned for the first table. For the&amp;nbsp; second table,&amp;nbsp; I try this same process, but I am not getting the number of selected records, I get the TOTAL number of records in the table which I dont care about.&amp;nbsp; I know I've seen this happen before but can't remember why it's happening. Thanks in advance for the help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.UpdateCursor(inPtMeasureTbl,("STREAM_CODE","SPECSTR","TYPE","MEAS","PROB"), "TYPE = 'MIDSP' " ) as mainCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = arcpy.GetCount_management(inPtMeasureTbl)
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = int(result.getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print count #this works fine
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for curRec in mainCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print "Working on AWC_CODE: %s&amp;nbsp; Specstr: %s&amp;nbsp; Meas: %f" % (curRec[0], curRec[1], curRec[3])&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Compare to # of line events occurring at this spot
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; srchExpr = "STREAM_CODE='%s' and F_MEAS &amp;lt;= %f and T_MEAS &amp;gt;= %f" % (curRec[0], curRec[3],curRec[3] )
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(inEventTbl,("STREAM_CODE","SPECLS","F_MEAS","T_MEAS"), srchExpr) as lkupCursor:&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numLineEvents = int(arcpy.GetCount_management(inEventTbl).getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print numLineEvents #THIS NUMBER IS THE TOTAL WHICH IS WRONG

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for curEventTbl in lkupCursor:
&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;&amp;nbsp; print "Found event: %s&amp;nbsp; Specstr: %s&amp;nbsp; Measures: %f , %f" % (curEventTbl[0],curEventTbl[1], curEventTbl[2], curEventTbl[3])&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:49:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-number-records-returned-by-2nd-cursor/m-p/630648#M49098</guid>
      <dc:creator>SkipRepetto</dc:creator>
      <dc:date>2021-12-12T02:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: get number records returned by 2nd cursor</title>
      <link>https://community.esri.com/t5/python-questions/get-number-records-returned-by-2nd-cursor/m-p/630649#M49099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would expect the second issue you're seeing because the creation of the cursor has no effect on the source data. I would also assume that the count you're getting for the first cursor is wrong unless your data happens to match the filter in the cursor. Have you tried creating a feature layer against the data using the filters you're providing to the cursor? Otherwise you can iterate through the cursor and get the count prior to looping through it again. I wrote up examples of this below, but note I didn't test either of these. They're just how I'm thinking this would work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Option A - Get the count using a table view or feature layer&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;ufields = ("STREAM_CODE","SPECSTR","TYPE","MEAS","PROB")
ufilter = "TYPE = 'MIDSP'"
with arcpy.da.UpdateCursor(inPtMeasureTbl, ufields, ufilter) as ucursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; utview = arcpy.management.MakeTableView(inPtMeasureTbl, "utable", ufilter)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ucount = int(arcpy.management.GetCount(uview).getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; for urow in ucursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cfields = ("STREAM_CODE","SPECLS","F_MEAS","T_MEAS")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cfilter =&amp;nbsp; "STREAM_CODE='{}' and F_MEAS &amp;lt;= {:.6f} and T_MEAS &amp;gt;= {:.6f}".format(*[urow[0], urow[3], urow[3]])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(inEventTbl, cfields, cfilter) as ccursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ctview = arcpy.management.MakeTableView(inEventTbl, "ctable", cfilter)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ccount = int(arcpy.management.GetCount(ctview).getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Line Events Count: {0}".format(count))
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for crow in ccursor:
&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;&amp;nbsp; print("Found event: {} Specstr: {} Measures: {:.6f} , {:.6f}".format(*row))&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Option B - Get the count from the cursor&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;ufields = ("STREAM_CODE","SPECSTR","TYPE","MEAS","PROB")
ufilter = "TYPE = 'MIDSP'"
with arcpy.da.UpdateCursor(inPtMeasureTbl, ufields, ufilter) as ucursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ucount = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; for _ in ucursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ucount += 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ucursor.reset()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for urow in ucursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cfields = ("STREAM_CODE","SPECLS","F_MEAS","T_MEAS")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cfilter =&amp;nbsp; "STREAM_CODE='{}' and F_MEAS &amp;lt;= {:.6f} and T_MEAS &amp;gt;= {:.6f}".format(*[urow[0], urow[3], urow[3]])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(inEventTbl, cfields, cfilter) as ccursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ccount = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for _ in ccursor:
&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;&amp;nbsp; ccount += 1&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;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ccursor.reset()
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Line Events Count: {0}".format(count))
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for crow in ccursor:
&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;&amp;nbsp; print("Found event: {} Specstr: {} Measures: {:.6f} , {:.6f}".format(*row))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:49:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-number-records-returned-by-2nd-cursor/m-p/630649#M49099</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2021-12-12T02:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: get number records returned by 2nd cursor</title>
      <link>https://community.esri.com/t5/python-questions/get-number-records-returned-by-2nd-cursor/m-p/630650#M49100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Freddie,&lt;/P&gt;&lt;P&gt;your first sentence was indeed fundamental to my problem:&lt;BR /&gt;"I would expect the second issue you're seeing because the creation of the cursor has no effect on the source data. I would also assume that the count you're getting for the first cursor is wrong unless your data happens to match the filter in the cursor."&amp;nbsp; I tested out that theory and indeed, the cursor has no effect on source data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had already implemented a manual counter as a work around - your "Option B" which of course works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Dec 2015 00:13:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-number-records-returned-by-2nd-cursor/m-p/630650#M49100</guid>
      <dc:creator>SkipRepetto</dc:creator>
      <dc:date>2015-12-10T00:13:30Z</dc:date>
    </item>
  </channel>
</rss>

