Thanks for all the suggestions. I've been trying arcpy.AlterField_management() for the most part.
@KevinBell1What you had didn't work verbatim. I think because my data sometimes has more than one underscore. Anytime I attempted to grab the value after the delimiter with split()[1] it told me Iist index out of range. So, I started using a combination of split() and partition().
I'm able to print out the values I want, but when I add the line to alter the field I get an error.
flds = arcpy.ListFields(r'...pathto\Outputs.gdb\testdelete')#full path to feature class
for f in flds:
mytuple = f.name.split("_")
if mytuple[0] == "USER": #if USER before the underscore
print(f.name.partition("_")[2]) #print what's after the underscore
arcpy.AlterField_management(flds, f.name, f.name.partition("_")[2])
else:
pass
print('pass me up')
pass me up
pass me up
pass me up
pass me up
pass me up
pass me up
pass me up
Reporting_Period
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-133-c6d9bc0ffe7b> in <module>
4 if mytuple[0] == "USER":
5 print(f.name.partition("_")[2])
----> 6 arcpy.AlterField_management(flds, f.name, f.name.partition("_")[2])
7 else:
8 pass
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in AlterField(in_table, field, new_field_name, new_field_alias, field_type, field_length, field_is_nullable, clear_field_alias)
5427 return retval
5428 except Exception as e:
-> 5429 raise e
5430
5431 @gptooldoc('AssignDefaultToField_management', None)
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in AlterField(in_table, field, new_field_name, new_field_alias, field_type, field_length, field_is_nullable, clear_field_alias)
5424 from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
5425 try:
-> 5426 retval = convertArcObjectToPythonObject(gp.AlterField_management(*gp_fixargs((in_table, field, new_field_name, new_field_alias, field_type, field_length, field_is_nullable, clear_field_alias), True)))
5427 return retval
5428 except Exception as e:
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
510 val = getattr(self._gp, attr)
511 if callable(val):
--> 512 return lambda *args: val(*gp_fixargs(args, True))
513 else:
514 return convertArcObjectToPythonObject(val)
RuntimeError: Object: Error in executing tool
Fields: