python - How to limit for loop iterations within cursor? -



python - How to limit for loop iterations within cursor? -

i using for loop within searchcursor iterate through features in featureclass.

import arcpy fc = r'c:\path\to\featureclass' arcpy.da.searchcursor(fc, ["fielda", "fieldb", "fieldc"]) cursor: row in cursor: # something...

i troubleshooting script , need find way limit iterations to, say, 5 rather 3500 configured. know basic way limit number of iterations in for loop follows:

numbers = [1,2,3,4,5] in numbers[0:2] print

however, approach not work when iterating on cursor object. method can utilize limit number of iterations of for loop within cursor object wrapped in with statement?

you utilize list comprehension grab , take first 5 rows need. check illustration below:

max = 5 #insert max number of iterations here arcpy.da.searchcursor(fc, ["fielda", "fieldb", "fieldc"]) cursor: output = [list(row) row in cursor][:max]

it of import note each row tuple output, list() method used create 2d list can used whatever need. if dataset 3500 rows, should trick in little time. hope helps!

python cursor arcpy

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -