0

I am trying to create in Field Calculator (arcmap) a function to assing a numeric value in a column (heighs) based on a text value from another column(building).

'Pre Logic' input box

def a(heighs, building):
 if (building=  '111'):
  return 50

 elif (building=  '112'):
  return 100

 else:
  return 1

'field =' box

a( !heighs! , !building! )

I am always getting this error: "Failed to execute. Parameters are not valid." "ERROR 000989:Python syntax error: Parsing error SyntaxError: invalid syntax (line2)

Is this a indentation error or is an error in the function that I am creating? How can I make the indentation on the Field Calculator window (tab don't work!!)? One space for each line?

  • 2
    The eqivalence operator is "==", but you're using the assignment operator ("="). BTW, best practice is FOUR spaces. – Vince May 15 '17 at 14:14
  • Exactly that! I try before with "==", but then maybe I got a indentation problem! Thanks – arturmlribeiro May 16 '17 at 8:35
1

As commented by @Vince, you're using the assignment operator = as opposed to the equality operator ==.

Use = when you want to assign a value. Use == when you want to test if two values are equal.

The error message you got told you exactly where the problem was. Line 2. It threw an error because of the operator. Of course, there is another error in your elif statement, but the interpreter hadn't gotten that far yet.

Your code should look like this (with standard four space indentation):

def a(heighs, building):
    if (building == '111'):
        return 50
    elif (building == '112'):
      return 100
    else:
      return 1

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.