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()
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()
I think the problem is nothing more than the indentation which controls the loops. I believe the code should be: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()
import arcpy in_feature = "3ans" near_feature = "PhysicoChimie3ans" cursor1 = arcpy.SearchCursor(in_feature, fields="NEAR_FID") for row1 in cursor1: data_to_get = row1.getValue("NEAR_FID") print data_to_get cursor2 = arcpy.SearchCursor(near_feature, fields="pH") for row2 in cursor2: if row2.getValue("FID") == data_to_get: print row2.getValue("ph"), "loop2" del row2,cursor2
del row2,cursor2
import arcpy in_feature = "3ans" near_feature = "PhysicoChimie3ans" cursor1 = arcpy.SearchCursor(in_feature, fields="NEAR_FID") for row1 in cursor1: data_to_get = row1.getValue("NEAR_FID") print data_to_get cursor2 = arcpy.SearchCursor(near_feature, fields="pH") for row2 in arcpy.SearchCursor(near_feature, fields="pH"): if row2.getValue("FID") == data_to_get: print row2.getValue("ph"), "loop2" del row2
with arcpy.SearchCursor(in_feature, fields="NEAR_FID")as cursor1: #loops here
Now the problem in that script is that I want to write the data extracted from the 2nd table in the 1st table (instead of just "printing" it"). I know I have to use an UpdateCursor but in don't understand how to use it properly when dealing with two tables instead of just one. Exemples I have seen are for taking a data in a field and writing something in another field inside the same table.
So instead of printing data_to_write, I want to write it in the table of in_feature in the field "ph"
Confused...