update.getValue(names) = row.getValue(names)
import arcpy, sys, traceback from arcpy import env env.overwriteOutput = True env.workspace = r"Z:\Test.gdb" arcpy.CreateTable_management(r"Z:\Test.gdb", "TABLE_E2_1_new") count = int(arcpy.GetCount_management("TABLE_E2_1_original").getOutput(0)) rows = arcpy.InsertCursor("TABLE_E2_1_new") x = 1 while x <= count: print x row = rows.newRow() rows.insertRow(row) x+=1 del row, rows, x tableList = arcpy.ListTables() for table in tableList: if table == "TABLE_E2_1_original": fieldList = arcpy.ListFields(table) for field in fieldList: if field.name not in ["OBJECTID", "TYPE", "Common_Name", "Scientific_Name", "Species"]: print field.name arcpy.AddField_management("TABLE_E2_1_new", field.name, "SHORT") elif field.name != "OBJECTID": print "Remaining " + field.name arcpy.AddField_management("TABLE_E2_1_new", field.name, "TEXT", "", "", 100) del table, tableList, fieldList, field searchRows = arcpy.SearchCursor("TABLE_E2_1_original") updateRows = arcpy.UpdateCursor("TABLE_E2_1_new") update = updateRows.next() fieldList = arcpy.ListFields("TABLE_E2_1_new") for row in searchRows: # List fields to get field name and pass into variable for calling into update cursor/search cursor below for field in fieldList: names = field.name update.getValue(names) = row.getValue(names) # Keep getting error "***can't assign to function call. update = updateRows.next() del update, updateRows, row, searchRows, names, field, fieldList
Solved! Go to Solution.
import arcpy baseWorkspace = r"Z:\Test.gdb" inputTable = "TABLE_E2_1_original" outputTable = "TABLE_E2_1_new" if arcpy.Exists(baseWorkspace + "\\" + outputTable): arcpy.Delete_management(baseWorkspace + "\\" + outputTable) print 'Deleted: %s' % baseWorkspace + "\\" + outputTable staticFields = ["OBJECTID", "TYPE", "Common_Name", "Scientific_Name", "Species"] arcpy.CreateTable_management(baseWorkspace, outputTable) print 'Output table created...' fieldList = arcpy.ListFields(inputTable) for field in fieldList: if field.name not in staticFields: print field.name arcpy.AddField_management(outputTable, field.name, "SHORT") elif field.name != "OBJECTID": print "Remaining " + field.name arcpy.AddField_management(outputTable, field.name, "TEXT", "", "", 100) del field print 'Added fields to new table...' sC = arcpy.SearchCursor(inputTable) iC = arcpy.InsertCursor(outputTable) for row in sC: row_new = iC.newRow() for field in fieldList: if field.name != "OBJECTID": value = row.getValue(field.name) row_new.setValue(field.name, value) iC.insertRow(row_new) del row_new del row, iC, sC, field, fieldList print 'Copied values to new table...' print 'Script complete.'
import arcpy baseWorkspace = r"Z:\Test.gdb" inputTable = "TABLE_E2_1_original" outputTable = "TABLE_E2_1_new" if arcpy.Exists(baseWorkspace + "\\" + outputTable): arcpy.Delete_management(baseWorkspace + "\\" + outputTable) print 'Deleted: %s' % baseWorkspace + "\\" + outputTable staticFields = ["OBJECTID", "TYPE", "Common_Name", "Scientific_Name", "Species"] arcpy.CreateTable_management(baseWorkspace, outputTable) print 'Output table created...' fieldList = arcpy.ListFields(inputTable) for field in fieldList: if field.name not in staticFields: print field.name arcpy.AddField_management(outputTable, field.name, "SHORT") elif field.name != "OBJECTID": print "Remaining " + field.name arcpy.AddField_management(outputTable, field.name, "TEXT", "", "", 100) del field print 'Added fields to new table...' sC = arcpy.SearchCursor(inputTable) iC = arcpy.InsertCursor(outputTable) for row in sC: row_new = iC.newRow() for field in fieldList: if field.name != "OBJECTID": value = row.getValue(field.name) row_new.setValue(field.name, value) iC.insertRow(row_new) del row_new del row, iC, sC, field, fieldList print 'Copied values to new table...' print 'Script complete.'