A feature class that I'm using as an input to a script was clipped from an enterprise SDE geodatabase, and has all of its field names in lower case. The script I'm using references all the field names in uppercase, as the input was previously clipped from a normal geodatabase instead.
Rather than update every line of the script that references a given field name (the script has about 1000 lines total). I came up with what I thought was a way to change the field names of the input clipped feature class to upper case- my code was as following:
capitalize_sde()
"""
I thought this would work to change all the field names of my "INPUT" feature class to upper case. Instead, the field names stayed the same, all in lower case letters. When I tested this in the debug console of vs code, it showed that the upper() function worked to my string variable upperfl, but the last line- arcpy.AlterField_management() didn't actually update the field.
If you know of any way to fix this problem, I'd greatly appreciate it!
Thanks for any help!
Solved! Go to Solution.
Field renaming (as well as renaming featureclasses) wont change the case if there isn't any other changes to the name. To do what you are wanting, append a _1 or something at the end of the uppercased name, alter the field, and then alter again to remove it. This was from another question I answered some time ago that was after the same thing:
def capitalize_fc_fnames(in_fc):
# capitalizes all field names for specified feature class
print("\nCapitalizing all field names for feature class..")
all_fields = [f.name for f in arcpy.ListFields(in_fc) if f.name not in ["Shape_Area", "Shape_Length", "Shape", "OID", "BLOB"]]
for fld in all_fields:
arcpy.management.AlterField(in_fc, fld, new_field_name=f'{fld.upper()}_cmon')
arcpy.management.AlterField(in_fc, f'{fld.upper()}_cmon', new_field_name=fld.upper())
You need to provide more information as to what INPUT actually is.
Alter Field (Data Management)—ArcGIS Pro | Documentation
either provide the full path to the featureclass or set the workspace as in the code examples above
Field renaming (as well as renaming featureclasses) wont change the case if there isn't any other changes to the name. To do what you are wanting, append a _1 or something at the end of the uppercased name, alter the field, and then alter again to remove it. This was from another question I answered some time ago that was after the same thing:
def capitalize_fc_fnames(in_fc):
# capitalizes all field names for specified feature class
print("\nCapitalizing all field names for feature class..")
all_fields = [f.name for f in arcpy.ListFields(in_fc) if f.name not in ["Shape_Area", "Shape_Length", "Shape", "OID", "BLOB"]]
for fld in all_fields:
arcpy.management.AlterField(in_fc, fld, new_field_name=f'{fld.upper()}_cmon')
arcpy.management.AlterField(in_fc, f'{fld.upper()}_cmon', new_field_name=fld.upper())
Thanks for the help, altering the field twice after appending something to the end worked!