Unless you need to skip a row, row1 = cursor1.next()
isn't needed when you're already in a loop like for row1 in cursor1:
. The loop will automatically go to the next record for you.
Next problem is that your cursor
cursor will complete its iteration after the first run of the cursor1
loop, so it needs to be reset so it starts over from the beginning. So replace row1 = cursor1.next()
with cursor.reset()
.
for row1 in cursor1:
for row in cursor:
if row1.getValue(field) == row.getValue(field):
if row1.getValue(maxfield) == row.getValue(field1):
cursor2.insertRow(row)
cursor.reset()
As it is written with the next()
and no reset
, it's going to do something like:
- Load the first row of
cursor1
- Load the first row of
cursor
- Check to see if the values in
field
match - Check to see if the values in
maxfield
andfield1
match - If they match, insert a row, and advance
cursor1
to the second row - Load the second row of
cursor
to do the same checks - Oops! We're not on the first row of
cursor1
anymore! - Every time we have we match, another row of
cursor1
gets skipped - Eventually, we finish all the rows of
cursor
- So the
for
loop advances to the next row ifcursor1
, which isn't the second row since it's been advanced by every match. - So now with what I assume is the 19th row of
cursor1
: - We want to loop the values of
cursor
with the for-loop - But the cursor has already been run to the end in the first loop
- The for-loop has nothing left to loop over so it skips the checks.