rows = arcpy.da.SearchCursor(someFC,someFields,someQuery) print (len(rows)) #I'm sure this used to work with the old cursors, but doesn't work with da.SearchCursor
Solved! Go to Solution.
rows = [row for row in arcpy.da.SearchCursor(someFC,someFields,someQuery)] print len(rows)
int(arcpy.GetCount_management(someFC).getOutput(0))
myFeatClass = r'C:\MyGDB\myFeatureClass' result = int(arcpy.GetCount_management(fc).getOutput(0)) print result
rowcount = 0 myFeatClass = r'C:\MyGDB\myFeatureClass' with arcpy.da.SearchCursor(myFeatClass, "*") as cursor: for row in cursor: count = count + 1 print rowcount
rowcount = 0 sql = "OBJECTID = 29821" myFeatClass = r'C:\MyGDB\myFeatureClass' with arcpy.da.SearchCursor(myFeatClass, "*", sql) as cursor: for row in cursor: count = count + 1 print rowcount
Thanks for the suggestions, but I'm looking to avoid a counter.
rows = [row for row in arcpy.da.SearchCursor(someFC,someFields,someQuery)] print len(rows)
int(arcpy.GetCount_management(someFC).getOutput(0))
result = int(arcpy.GetCount_management(fc).getOutput(0))
fc = r'c:\path\to\fc' w = '"OBJECTID" < 10' lr = arcpy.MakeFeatureLayer_management(fc, 'tmp_layer', w).getOutput(0) result = int(arcpy.GetCount_management(lr).getOutput(0)) arcpy.Delete_management(lr) # deletes the layer, not the feature class data # result is 9
import arcpy, time fc = r"C:\csny490\overlay_20130620\ldo_20130620\ldo_database.gdb\crew_code" time1 = time.clock() result = int(arcpy.GetCount_management(fc).getOutput(0)) time2 = time.clock() print "GetCount (" + str(result) + "), took " + str(time2-time1) + " seconds..." time1 = time.clock() result = len([r[0] for r in arcpy.da.SearchCursor(fc, ["OID@"])]) time2 = time.clock() print "SearchCursor (" + str(result) + "), took " + str(time2-time1) + " seconds..."