Hello, I am trying to either:
a) Alter a field name and looping through several tables to change many (similar) names to the same name, or
b) calculate a field. Both seem very simple, but I am not understanding the errors being thrown, or why they are not working.
Example a) Alter a field. Code runs, but does not actually alter the field name
Code:
import acrpy
# Set workspace
arcpy.env.workspace = r'G:\G_and_E_spp\E_Spp\e_combine_tables.gdb'
# Loop through tables looking for a field named '*_CON'
fcList = arcpy.ListFeatureClasses() # Get a list of feature classes
for fc in fcList: # Loop through feature classes
fieldList = arcpy.ListFields(fc) # Get a list of fields for each feature class
for field in fieldList: # Lloop through each field
if field.name.lower() =='aADSAx_CON':
arcpy.management.AlterField(fc, field.name, 'aADSAx_CON', 'sp_con', 'species condition')
b) Calculate field
Code:
import arcpy
inTab = r"G:\G_and_E_spp\E_Spp\combine_tables_dbf\aADSAx_CONUS_0123_2001v1_2012.dbf"
expr_1 = !sp_con! = !aADSAx_CON!
arcpy.CalculateField_management(inTab,"aADSAx_CON",expr_1,"PYTHON3")
Error:
RuntimeError Traceback (most recent call last)
In [69]:
Line 4: arcpy.CalculateField_management(inTab,"aADSAx_CON",expr_1,"PYTHON3")
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in CalculateField:
Line 5711: raise e
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in CalculateField:
Line 5708: retval = convertArcObjectToPythonObject(gp.CalculateField_management(*gp_fixargs((in_table, field, expression, expression_type, code_block, field_type, enforce_domains), True)))
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py, in <lambda>:
Line 512: return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool
Any help very much appreciated!!