Select to view content in your preferred language

Selecting rows using For Loop in python.

896
3
09-30-2013 04:11 AM
MANESK
by
Occasional Contributor
I've a set of 10000 records in which i've to select only alternate set of 100 records which
has continuous FID..(i.e selection should be 1 to 100, 201 to 300,401 to 500..likewise).. on a single execution..

i need a script in python or vb script ..
Pls suggest...

i'm a newbie to python..
Tags (2)
0 Kudos
3 Replies
markdenil
Frequent Contributor
Use Make Feature Layer or Make Table View to create a sub set of your feature class or table.
The where clause in these tools will grab only the features you want to process.
The where can be set up in a variety of ways,
largely dependant on how clever you want to appear to someone reading your code.

the simplest might be to use a nested python list of the discrete start and stop points for your ranges
InputFC_var = ...full path to the FC...
outputLyr_var = "outputLyr"

rangeList = [
        [1, 100],
        [101, 200],
        [201, 300]]

for r in rangeList:
    whereClause = ' "FID" >= r[0] AND "FID" <= r[1] '
    arcpy.MakeFeatureLayer_management(InputFC_var, outputLyr_var, whereClause)
    ...other stuff you want to do...

0 Kudos
MANESK
by
Occasional Contributor
Thanks for your reply...

I ve a set of around 50,000 records.. If i ve to specify the range ,it'll take some time..

So any other option..
kindly reply..
0 Kudos
RDHarles
Regular Contributor
This will get you the numbers you are looking for.  Then you can use the variables "lowRange" & "highRange" to select those records.

set=1
lowRange=1
for highRange in range(100,50001,100):
    set=set+1
    if set % 2 == 0:
        print "From "+str(lowRange)+" To "+str(highRange)
    lowRange=lowRange+100
0 Kudos