Hello All,
The short and sweet version is this:
I want to:
I use the Priority field as the Case field in the next tool (summary stats) and
some of the shapefiles have the field as "Priority_1" or something similar.
What prints in the console is this:
"The priority field was named [<Field object at 0x19b708f0[0x18f993b0]>] and will be renamed."
So clearly it is not reading the field names properly.
I have read about arcpy.Alterfield_management, but it reportedly does not work with shapefiles.
I have also tried iterating over the fields using the field index and looking for the field name I want, but no luck.
Thanks for your help.
The short and sweet version is this:
I want to:
- Read the list of fields in a shapefile
- check for a field starting with "Pri*"
- If it is not named "Priority", I want to rename them to "Priority"
I use the Priority field as the Case field in the next tool (summary stats) and
some of the shapefiles have the field as "Priority_1" or something similar.
Code:
prifield = arcpy.ListFields(preparedfeatures, 'Pri*')
try:
if prifield != "Priority":
arcpy.AddWarning('The priority field was named ' + str(prifield) + " and will be renamed.")
arcpy.AddField_management(preparedfeatures, "Priority", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(preparedfeatures, "Priority", prifield , "PYTHON_9.3", "")
except:
arcpy.AddWarning(arcpy.GetMessages())
continue
What prints in the console is this:
"The priority field was named [<Field object at 0x19b708f0[0x18f993b0]>] and will be renamed."
So clearly it is not reading the field names properly.
I have read about arcpy.Alterfield_management, but it reportedly does not work with shapefiles.
I have also tried iterating over the fields using the field index and looking for the field name I want, but no luck.
Thanks for your help.