I have a shapefile with only 4 rows in it. I already could filter it so I have only 2 left. I need these sorted by the 'length' field, then take the first and second row to save in to individual files. Here is the code for sorting:
import arcpy
fc = 'C:\\Users\\test.shp'
fields = ['length', 'FID']
expression = arcpy.AddFieldDelimiters(fc, "length") + " > 1000"
for row in sorted(arcpy.da.SearchCursor(fc, fields,)):
print('{0}, {1}'.format(row[0], row[1]))
For saving in to the new file:
arcpy.FeatureClassToFeatureClass_conversion(?, outLocation,
outFeatureClass,)
How can I make the search cursor to show first only the lower value row, then the higher one? (order doesn't matter)
How can I select the number 1 row, then the number 2 row?
Best Answer
You do not state what your license level is; this is always important as it dictates the solution. Having said that, consider using the Sort tool (which requires an Advanced license). More information can be found here.