import arcpy fc = "C:/Users/hchapa.LRGVDC911.000/Documents/ArcGIS/Default.gdb/Test_Shapefile_SpatialJoin" field = "parcel_1" fc2 = "C:/GIS_DATA/Test_Shapefile.shp" field2 = "parcel" value = [] cursor = arcpy.SearchCursor(fc) UpdateCursor = arcpy.UpdateCursor(fc2) for row in cursor: value = row.getValue(field) for row2 in UpdateCursor: row2.setValue(field2, value) UpdateCursor.updateRow(row2) print "Done"
Solved! Go to Solution.
import arcpy fc = "C:/Users/hchapa.LRGVDC911.000/Documents/ArcGIS/Default.gdb/Test_Shapefile_SpatialJoin" field = "parcel_1" fc2 = "C:/GIS_DATA/Test_Shapefile.shp" field2 = "parcel" value = [] #You should remove this line. It's not needed. cursor = arcpy.SearchCursor(fc) UpdateCursor = arcpy.UpdateCursor(fc2) tempRows = [] for row in cursor: value = row.getValue(field) tempRows.append(value) c = 0 #use as a counter for row2 in UpdateCursor: value = tempRows#assumes both this are in the exact same order row2.setValue(field2, value) UpdateCursor.updateRow(row2) c+=1 #count up by 1 del TempRows print "Done"
import arcpy fc = "C:/Users/hchapa.LRGVDC911.000/Documents/ArcGIS/Default.gdb/Test_Shapefile_SpatialJoin" field = "parcel_1" fc2 = "C:/GIS_DATA/Test_Shapefile.shp" field2 = "parcel" value = [] #You should remove this line. It's not needed. cursor = arcpy.SearchCursor(fc) UpdateCursor = arcpy.UpdateCursor(fc2) tempRows = [] for row in cursor: value = row.getValue(field) tempRows.append(value) c = 0 #use as a counter for row2 in UpdateCursor: value = tempRows#assumes both this are in the exact same order row2.setValue(field2, value) UpdateCursor.updateRow(row2) c+=1 #count up by 1 del TempRows print "Done"
import arcpy fc = "C:/Users/hchapa.LRGVDC911.000/Documents/ArcGIS/Default.gdb/Test_Shapefile_SpatialJoin" field = "parcel_1" fc2 = "C:/GIS_DATA/Test_Shapefile.shp" field2 = "parcel" value = [] #You should remove this line. It's not needed. cursor = arcpy.SearchCursor(fc) UpdateCursor = arcpy.UpdateCursor(fc2) # fetch the 1st row, for both search/update cursors row = cursor.next() row2 = UpdateCursor.next() while row: row2.setValue(field2, row.getValue(field)) UpdateCursor.updateRow(row2) # advance both cursors to next row obj row = cursor.next() row2 = UpdateCursor.next() del cursor, UpdateCursor print "Done"
I think you have your 'for' loops a little scrambled.
For each row in the search cursor, you're writing to every row in the update cursor. It probably accepts all the data once, which is why you're only getting the first data (over and over again I suspect).
There are many good ways to traverse both lists at the same time, but a simple solution might be to just use a temporary list. Here's what I would try:import arcpy fc = "C:/Users/hchapa.LRGVDC911.000/Documents/ArcGIS/Default.gdb/Test_Shapefile_SpatialJoin" field = "parcel_1" fc2 = "C:/GIS_DATA/Test_Shapefile.shp" field2 = "parcel" value = [] #You should remove this line. It's not needed. cursor = arcpy.SearchCursor(fc) UpdateCursor = arcpy.UpdateCursor(fc2) tempRows = [] for row in cursor: value = row.getValue(field) tempRows.append(value) c = 0 #use as a counter for row2 in UpdateCursor: value = tempRows#assumes both this are in the exact same order row2.setValue(field2, value) UpdateCursor.updateRow(row2) c+=1 #count up by 1 del TempRows print "Done"
This solution assumes both list contain the same number of records in the same order. If this is not the case you will need a way or relating the records between the two table (a Join may work well in that case).
Good luck, let us know how it goes!
~Josh