[GIS] Counting Characters using Field Calculator – ArcMap

arcgis-desktoparcmapfield-calculatorpython-parser

I am trying to use field calculator to populate a column based on the the number of characters in another column. I am using the Python Parser. I am not sure if the .count() function is appropriate in this case or if I am even using it right.

My pre-logic script is:

def reclass(f1):
     if f1.count() >= 4:
         return "Yes"
      else:
         return "No"


Label = reclass( !HUB! )

Best Answer

I would make two changes:

  1. Make sure your indentation is correct
  2. Use len() to count the characters. Make sure you are writing to a text field.

def reclass(f1):
     if len(f1) >= 4:
         return "Yes"
     else:
         return "No"

Label = reclass( !HUB! )
Related Question