4

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! )
8

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! )
0

Select by Attributes: char_length(FIELD) >= number

Field Calculate on the selected records

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 1
    This Answer was flagged up as low quality due to its brevity. I think you should edit it to explain that you are suggesting an alternative to using the Python Parser of the Field Calculator. – PolyGeo Apr 4 '14 at 21:46

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.