I have a table(Table1) that i need to update on a regular basis by comparing/matching the records in the (Table1) to the table (Table2) based on field "Street" of Table1 and "FullStName" of table two. If theirs NOT a match it then updates the table1 based on the NOT matched from the table and I also need it to add "FullStName" have have "RES", "Reserved", "proposed" in the "status" field of table2. I need to add the missing names of tabel2 to table 1. Hopefully it make sense.
This is what i have but i am not sure i am doing it right...
import arcpy
from arcpy import env
arcpy.env.workspace = r"C:\Temp\Default.gdb\RoadNames"
Rtable = "table1"
table1 = "table2"
fcIncident = []
tableIncident = []
with arcpy.da.SearchCursor(Rtable, ["Street"]) as cursor:
for row in cursor:
fcIncident.append(row[0])
del row, cursor
with arcpy.da.SearchCursor(table1, ["FULLSTNAME", "STATUS"]) as cursor:
for row in cursor:
if row[1] in ("RES", "Reserved", "proposed"):
if not row[0] in fcIncident:
tableIncident.append(row[0])
del row, cursor
arcpy.MakeTableView_management(table1, "tblView")
for ID in tableIncident:
arcpy.SelectLayerByAttribute_management("tblView", "ADD_TO_SELECTION", "FULLSTNAME = " + str(ID))
Solved! Go to Solution.
Shouldn't the insertCursor be on Table1 since that is the table i am needing to update?
I am getting an error.
insertCursor.insert(i)
AttributeError: 'da.InsertCursor' object has no attribute 'insert'
table1List = []
with arcpy.da.SearchCursor(table1, ['Street']) as cursor:
for row in cursor:
table1List.append(row[0])
del cursor
#list of fields whose will need to be imported into table2
fields = ['FULLSTNAME']
#list of values from table1 to inject into table2
ids = []
with arcpy.da.SearchCursor(table2, ['FULLSTNAME']) as cursor:
for row in cursor:
if row[0] not in table1List:
ids.append(row[0:])
del cursor
#create insert cursor variable
insertCursor = arcpy.da.InsertCursor(table2,fields)
#loop through items in ids list and insert into table
for i in ids:
insertCursor.insert(i)
del insertCursor
Yes, you're correct. Change 'table1' to 'table2' in line 19.
Oops... regarding the error: change 'insertCursor.insert(i)' in line 23 to 'insertCursor.insertRow(i)'.
Do you mean change 'table2' to 'table1' in line 20?
I have inserted the "Row" in insertCursor.insertRow(i)