1

I am trying to change field name of shapefile using AlterField (Management) tool for multiple feature class and multiple field name (same in all fc)

import arcpy  
from arcpy import env  
env.workspace = r"C:\Users\To Fix.gdb"  

for fc in arcpy.ListFeatureClasses("*"):  
    try:  
        arcpy.AlterField_management(fc, "Column_Lab","201701E","")
        arcpy.AlterField_management(fc, "_1","201701G","")
        arcpy.AlterField_management(fc, "_12","201702E","")
        arcpy.AlterField_management(fc, "_123","201702G","")
        arcpy.AlterField_management(fc, "_1234","201703E","")
        arcpy.AlterField_management(fc, "_12345","201703G","")
    except:  
        pass

Nothing happens when I run the script. However when I use

arcpy.AlterField_management(fc, "Column_Lab","","201701E")

It changes the alias successfuly.

Using ArcGIS 10.2 Advance

Code adopted from https://community.esri.com/thread/104033

2
  • Do you want to change the alias name or the field name itself? – ahmadhanb Oct 1 '18 at 5:31
  • Field Names only. – 789789 Oct 1 '18 at 5:36
2

I think the problem is that you want to change the field name to start with number which is not acceptable. As per the technical article: FAQ: What characters should not be used in ArcGIS for field names and table names?, It says among other limitations that:

  • Do not start field or table names with an underscore or a number.

Try to start the field names with letters then add numbers.

3
  • This worked. Weird because when I name fields starting with number when adding new fields, it works with any issue. Thx! – 789789 Oct 1 '18 at 5:53
  • 1
    When you add a new field starting with numbers, arcpy internally validate the field name and add underscore before the numbers, that is why it worked. But if you enforce the field to have numbers at the begining, it gives an error that it is not possible. – ahmadhanb Oct 1 '18 at 5:56
  • Also beware of schema locks 789789, which is clearly not the case here but can be frustrating for beginners: if you have a feature class or table in the database open in ArcMap you can't modify the schema of the other feature classes, if you have previewed the data in ArcCatalog a lock can still persist. You can find locks, but not free them, by looking for the lock files in shapefiles or file geodatabases with your favourite (or default) file browser, read more here desktop.arcgis.com/en/arcmap/10.3/manage-data/… – Michael Stimson Oct 1 '18 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.