0

Using ArcMap 10.4 here and having some trouble running some python code in the field calculator.

I am trying to populate one text field based on the value of another text field. Here is what I am entering into the field calculator:

enter image description here

When I attempt to run this I get the error:

enter image description here

I am using 2 spaces for the 'if' line and 4 spaces for the 'return' line. Maybe I'm missing something big, brand new to coding here so any help would be great.

  • 1
    Give four spaces a go. If not try tabs. – Brynne Aug 4 '17 at 16:03
2

A single = sign is for assignment, == is for comparison. Change your if statement to if luCode == 'BF':.

4 space indentation is suggested, but not required. Consistency within an indented block however, is required.

  • Hmm unfortunately that didn't work. After using the == I got error 999999 @bjorn – Tigerwoulds Aug 4 '17 at 17:43
  • Got it to work. It was a combination of using the == and using a 4 space indentation for the 'if' line and 6 for the 'return'. Not sure why it was required in this case. Thanks for your help! @bjorn – Tigerwoulds Aug 4 '17 at 17:59
  • @Tigerwoulds If you consider my answer to be the correct one you should mark it as such so that others can benefit. – Bjorn Aug 4 '17 at 18:03
0

The answer is 2 parts:

  1. As @Bjorn mentioned, I needed to use an == as opposed to an =

  2. I am missing an 'else' statement which is preventing the code from running; As soon as I added it, everything worked as it should. Spacing needed to be consistent but 2 vs 4 space indentation wasn't a factor.

  • You do not need an else there, it is implicit. Anything return ing after your if block will function as such. – fatih_dur Aug 6 '17 at 16:06
  • I get the same error unless I include an 'else return none' at the end – Tigerwoulds Nov 17 '17 at 15:51

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.