1

I am trying to perform a batch of Altering field names through a stand alone python script using Arcpy but it seems I am making a basic mistake in my python code. Using a list I refer to the original field names and with another list I refer to the new field names. When I alter the fields through arcpy.AlterField_management I refer to elements in both lists.

When I run the script, I get the error that an 'Invalid value type for parameter field' is used.

What mistake am I making here?

This is the script:

import arcpy
orig_fieldName_List = ['C1S1_N_VL_SFS_cwIS', 'C1S1_R_VL_HPR_cwIS', 'C1S1_N_VL_APT_cwIS']
new_fieldName_List = ['C_N_SFS', 'C_R_HPR', 'C_N_APT']

fc = r'C:\Users\Jelle\My Documents\Test.gdb\test'
fieldList = arcpy.ListFields(fc)
for field in fieldList:
    if field.name == orig_fieldName_List[0]:
        arcpy.AlterField_management(fc, field, new_fieldName_List[0], new_fieldName_List[0])
    if field.name == orig_fieldName_List[1]:
        arcpy.AlterField_management(fc, field, new_fieldName_List[1], new_fieldName_List[1])
    if field.name == orig_fieldName_List[2]:
        arcpy.AlterField_management(fc, field, new_fieldName_List[2], new_fieldName_List[2])

1 Answer 1

2

Despite the help file saying that the field parameter is of type Field it actually takes a string which is the field name, ESRI need to update their help file... Hopefully someone is reading this?

So this:

arcpy.AlterField_management(fc, field, new_fieldName_List[0], new_fieldName_List[0])

becomes this:

arcpy.AlterField_management(fc, field.name, new_fieldName_List[0], new_fieldName_List[0])

1
  • oh wauw, thank you! This worked! I certainly made use of ESRI's help file. I didn't expect, however, the help file would actually be wrong. First time I experience this. Commented Mar 20, 2015 at 17:55

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.