Using ArcGIS 10.1 for Desktop, I try to calculate a field using an 'if' statement in the field calculator. Here is my code :

MyField_2 = def Reclass(!MyField_1!)

Python 9.3

#Code Block
def Reclass(MyField1) :
    if MyField1 == -1 :
        return 0
    else :
        return !shape.area!

But I have an error returning !shape.area!. How can I fix that ?

  • I think !shape.area! also needs to be an argument in your Reclass function. But can you please post the error?
    – ustroetz
    Nov 6, 2013 at 23:50
  • I have a 00089 error "Python parsing error line 5" Nov 6, 2013 at 23:56

3 Answers 3


Instead of using a code block, you should be able to just do...

0 if !MyField_1! == -1 else !shape.area!

shape_area has to be an argument in your Reclass function.

Your expression should look like this:

Reclass( !MyField_1!,!shape.area!)

And your script code like this:

def Reclass(MyField1,shape_area):
 if MyField1 == -1:
   return 0
   return (shape_area)

You are receiving an error because shape isn't being referenced.

One way to solve it would be to pass two parameters to your reclass function, like @ustroetz mentioned. The following code does this:

Reclass(!MyField_1!, !shape.area!)

#Code block
def Reclass(test_field, shape):
  if test_field == -1:
    return 0
    return shape

#Or alternatively,
def Reclass(test_field, shape):
  return 0 if test_field == -1 else shape

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.