I have a field that contains street names and a second field called COUNT. I need to perform a Python field calculation on the COUNT field that counts the number of characters in the STREET_NAME field. For example if the street name is Main St then the COUNT field would be 7.
How about via the python option in the field calculator?
- Create the count field as Integer.
In the field calculator -
And to round things out with a cursor example...
import arcpy # Create update cursor for feature class rows = arcpy.UpdateCursor(r"C:\path\to\your\featureclass") for row in rows: row.COUNT = len(row.STREET_NAME) rows.updateRow(row) # Delete cursor and row objects to remove locks on the data del row del rows
arcpy.CalculateField_management("<file>", "COUNT", "len(!STREET_NAME!)", "PYTHON_9.3")
arcpy.CalculateField_management("<file>", "COUNT", "len([STREET_NAME])", "VB")
Since you are dealing with street names, I'm assuming that the field is already a string.