import arcpy data = r'D:\GIS\DataBase\misc.gdb\CLI_N' lyr = 'temp' arcpy.MakeFeatureLayer_management(data, lyr, 'OBJECTID < 100') print(arcpy.GetCount_management(lyr)) count = 0 cursor = arcpy.da.SearchCursor(lyr, 'OBJECTID', 'OBJECTID < 10') for _ in cursor: count += 1 print(count)
>>> 99 99
Solved! Go to Solution.
NIM076948 The arcpy.da.SearchCursor() where clause does not work with a table view
import arcpy data = r'D:\GIS\DataBase\misc.gdb\CLI_N' lyr = 'temp' arcpy.MakeFeatureLayer_management(data, lyr, 'OBJECTID < 100') print(arcpy.GetCount_management(lyr)) count = 0 arcpy.SelectLayerByAttribute_management(lyr, 'NEW_SELECTION', 'OBJECTID < 10') cursor = arcpy.da.SearchCursor(lyr, 'OBJECTID') for _ in cursor: count += 1 arcpy.SelectLayerByAttribute_management(lyr, 'CLEAR_SELECTION') print(count)
>>> 99 9 >>>
do you only have 99 features in that fc?
I can't seem to get the where clause to take on my FC, it always returns all records in the data.
It seems to work if I put my where clause on a different field, but can't get it to honor a where clause on OBJECTID ?????
R_
Weird, if I calculate my "other" field equal to OBJECTID, it won't honor that now either. Set it back to sequential numbers and it works. However, the makefeaturelayer never seems to report the same number of features that the same select query, on the same dataset in ArcMap.
Makefeature either seems to ignore my query and returns all results (as if I use OBJECTID) or, will return fewer results than actually match the query. (Finds 129 where "rec" <= 150 after sequentially calculating the rec field from 1 to 2110) Exact same "select by attributes" in ArcMap returns the 150 that actually match the query.
R_
NIM076948 The arcpy.da.SearchCursor() where clause does not work with a table view
import arcpy data = r'D:\GIS\DataBase\misc.gdb\CLI_N' lyr = 'temp' arcpy.MakeFeatureLayer_management(data, lyr, 'OBJECTID < 100') print(arcpy.GetCount_management(lyr)) count = 0 arcpy.SelectLayerByAttribute_management(lyr, 'NEW_SELECTION', 'OBJECTID < 10') cursor = arcpy.da.SearchCursor(lyr, 'OBJECTID') for _ in cursor: count += 1 arcpy.SelectLayerByAttribute_management(lyr, 'CLEAR_SELECTION') print(count)
>>> 99 9 >>>