Hey folks,I am trying to set a python script to:- List fields in a table
- Add a new field based on the current field by adding a "_1" to the end (i.e. if I have a number of fields named a1, b1, c1, etc. I want to add some new fields called a1_1, b1_1, c1_1, etc)
- Field calculate the new field based on it's original field (i.e. calculate a1_1 from the values in a1, calculate b1_1 with the values from b1 and so on)
- Delete the original field
The fields are being added perfectly, but when I go to calculate the new fields based on the old, it keeps erroring out with no real traceback message:PYTHON ERRORS:
Traceback info:
File "Z:\ESRI\Python\Test Scripts\SpeciesTable.py", line 25, in <module>
arcpy.CalculateField_management(table, fieldnew, field, "VB", "")
Error Info:
Object: Error in executing tool
ArcPy ERRORS:
I have a feeling it doesn't like the variable for the new field, but I've played with a number of different approaches and it doesn't seem to work. Also, I thought it was because the field types are different (i.e. all the original fields are TEXT or DOUBLE. The new fields are all SHORT). I tested this by manually adding the fields and field calculating from the attribute table and that seems to work fine. My script is as follows:import arcpy, sys, traceback from arcpy import env env.overwriteOutput = True env.workspace = r"C:\data\temp.gdb" tableList = arcpy.ListTables() for table in tableList: #print table if table == "TestTable": fieldList = arcpy.ListFields(table) for field in fieldList: if field.name not in ["OBJECTID", "TYPE", "Common_Name", "Scientific_Name", "Species"]: #print field.name fieldnew = field.name + "_1" #print fieldnew arcpy.AddField_management(table, fieldnew, "SHORT") arcpy.CalculateField_management(table, fieldnew, field, "VB", "") arcpy.DeleteField_management(field) del field, fieldList, fieldnew
Thanks,Mike