I have written a python script that is supposed to basically loop through selected records of a feature class. Here's a sample of what a table looks like:
OBID STID FL TL
1 1 0 9
2 1 8 19
3 2 3 23
4 3 0 0
5 1 21 29
6 3 0 11
7 1 27 31
8 3 13 19
Here's what I'm trying to do:
Create a SearchCursor (for main file) and InsertCursor (for new file)
Sort all records by STID, FL and TL in order with the SearchCursor
Record TL for the first row and move onto next row
Record STID and FL in a variable
Compare current FL to previous TL
If FL<=TL, export both rows to new table with InsertCursor
Continue until current STID is equal to previous STID. If not, go back to step 3 (ie, repeat the process for new STID)
And here's the code I wrote which is not working:
import arcpy
arcpy.env.workspace = "c:\\temp\\test.mdb"
abc = arcpy.SearchCursor("road","","","STID;FL;TL","STID A;FL A;TL A")
first = 1
for row in abc:
if first != 1:
spid = row.getValue("STID")
frl = row.getValue("FL")
if spid == prev:
if frl <= trl:
print spid, frl
prev = row.getValue("STID")
trl = row.getValue("TL")
else:
prev = row.getValue("STID")
trl = row.getValue("TL")
else:
prev = row.getValue("STID")
trl = row.getValue("TL")
first = 0
del row
del abc
