Solved! Go to Solution.
import arcpy from arcpy import env env.workspace = r"C:\temp\python\test.gdb" table1 = "Gages" table2 = "Mains" table1List = [] #append IDs to list rows = arcpy.SearchCursor(table1) for row in rows: table1List.append(row.getValue("ID")) del row, rows table2List = [] #iterate through list and find related records for n in table1List: rows = arcpy.SearchCursor(table2) for row in rows: if n == row.ID: #append related records to a new list table2List.append(row.X) table2List.append(row.Y) print str(n) + "\n\t" + str(table2List) #clear list for next ID table2List = [] del row, rows
import arcpy from arcpy import env env.workspace = r"C:\temp\python\test.gdb" table1 = "Gages" table2 = "Mains" table1List = [] #append IDs to list rows = arcpy.SearchCursor(table1) for row in rows: table1List.append(row.getValue("ID")) del row, rows table2List = [] #iterate through list and find related records for n in table1List: rows = arcpy.SearchCursor(table2) for row in rows: if n == row.ID: #append related records to a new list table2List.append(row.X) table2List.append(row.Y) print str(n) + "\n\t" + str(table2List) #clear list for next ID table2List = [] del row, rows