AnsweredAssumed Answered

get number records returned by 2nd cursor

Question asked by srepetto on Dec 9, 2015
Latest reply on Dec 9, 2015 by srepetto

So I want to get the number of records in  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  second table,  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.  I know I've seen this happen before but can't remember why it's happening. Thanks in advance for the help.


with arcpy.da.UpdateCursor(inPtMeasureTbl,("STREAM_CODE","SPECSTR","TYPE","MEAS","PROB"), "TYPE = 'MIDSP' " ) as mainCursor:
    result = arcpy.GetCount_management(inPtMeasureTbl)
    count = int(result.getOutput(0))
    print count #this works fine
    for curRec in mainCursor:
        #print "Working on AWC_CODE: %s  Specstr: %s  Meas: %f" % (curRec[0], curRec[1], curRec[3])            
        #Compare to # of line events occurring at this spot
        srchExpr = "STREAM_CODE='%s' and F_MEAS <= %f and T_MEAS >= %f" % (curRec[0], curRec[3],curRec[3] )
        with arcpy.da.SearchCursor(inEventTbl,("STREAM_CODE","SPECLS","F_MEAS","T_MEAS"), srchExpr) as lkupCursor:              
            numLineEvents = int(arcpy.GetCount_management(inEventTbl).getOutput(0))
            print numLineEvents #THIS NUMBER IS THE TOTAL WHICH IS WRONG

            for curEventTbl in lkupCursor:
                print "Found event: %s  Specstr: %s  Measures: %f , %f" % (curEventTbl[0],curEventTbl[1], curEventTbl[2], curEventTbl[3])