Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

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

$
0
0
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.


Code:

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()


Viewing all articles
Browse latest Browse all 2485

Trending Articles