Greetings,
I have a script that copies fields from on feature class to another. But it stops running if it encounters a field name greater than 10 characters in the source file. I am wondering if it's possible to trim the field name to let the program keep running. Something like this:
... shp = 'WillCounty_Street_09282018.shp'
... index = 8
... fields = arcpy.ListFields(shp)
... for field in fields:
... print ("name is", field.name, "length is", len(field.name))
... if len(field.name) > index:
... field.name = field.name[0: index+1:]
I made the index = 8 because the the feature class I am testing has no field names greater than 10. Of course that code works only works with strings. It runs but does not do the job of trimming the field names. Is it possible to do this?
It is a shapefile problem, gdb featureclass tables don't have this problem
but you could include ValidateFieldName in your code
Validating table and field names in Python—ArcPy Get Started | ArcGIS Desktop