gobtron

for loop in a for loop... I'm stuck!

Discussion created by gobtron on Mar 17, 2014
Latest reply on Mar 31, 2014 by FLBB
Hi! So I am new to python scripting, and after a few hours being stuck somewhere in my code, I require your help!

For some reason, the code goes in the 2nd loop only the first time. Then the first loop finishes without going into the second.
Loop 1 is supposed to read each row of the attribute table, ine the NEAR_FID field. Then, it reads a second attribute table and it does an action when NEAR_FID (from 1st table) == FID (from 2nd table).

What's wrong? I can't figure it out.


import arcpy
in_feature = "3ans"
near_feature = "PhysicoChimie3ans"

cursor1 = arcpy.SearchCursor(in_feature, fields="NEAR_FID")
cursor2 = arcpy.SearchCursor(near_feature, fields="pH")
                
for row1 in cursor1:  
  data_to_get = row1.getValue("NEAR_FID")
  print data_to_get
  for row2 in cursor2:
    if row2.getValue("FID") == data_to_get:
      print row2.getValue("ph"), "loop2"
      cursor2.reset()

Outcomes