2

I'm trying to run a field calculation using multiple fields in a table as well as independent numeric values with python code in the field calculator window. I've included the first 7 lines of the code below. I'm not getting any syntax errors, but I'm also not getting any results. The other fields used as variables include: Appraised_Value, Ag_value, and TaxRate_Municipal Not sure how to fix it.

Pre-Logic Script Code:

def Reclass( Exemp_Code_Int ) :
 if (Exemp_Code_Int == '0') :
  return (Appraised_Value / 100) * TaxRate_Municipal
 elif (Exemp_Code_Int == '2') :
  return (Ag_Value / 100) * TaxRate_Municipal
 elif (Exemp_Code_Int == '4') :
  return 0

Codeblock looks like this:

 Reclass( !Exemp_Code_Int! )

Screenshot too: enter image description here

  • You need to pass those other fields into the function as arguments. In field calculator you do that by typing !field_name!. In your current method, they are not in scope. – brock Nov 16 '15 at 20:59
4

All fields have to be included in the Reclass definition to be used by the calculation.

Reclass(!Exemp_Code_Int!, !Appraised_Value!, !TaxRate_Municipal!, !Ag_Value!, etc.)

Then those variables have to be included in the def of Reclass.

def Reclass(Exemp_Code_Int, Appraised_Value, TaxRate_Municipal, Ag_Value, etc.)

Also, if Exem_Code_Int is actually an integer value, then the logical comparison value cannot be a string. I.e.,

if (Exemp_Code_Int == '0'):

must become:

if (Exemp_Code_Int == 0):

  • +1 about integer/string checking. Similarly @FelixTX83, unless you want floor division (i.e, 5/2 in python returns 2), you need one of your values to be a float. The easiest way is probably to change your code to x/100.0 – Paul Nov 16 '15 at 20:55
  • Eureka! Thank you so much Richard Fairhurst! You hit three nails right on the head. I've tried with a small sample and I'll apply it to the rest of the script later today. Thanks again and well done! – FelixTX83 Nov 16 '15 at 21:36
  • This is the first question I've ever posted on here, so is there some way to mark this question as answered? – FelixTX83 Nov 16 '15 at 21:37
  • @FelixTX83 from the Tour you will learn that the Accept button serves that purpose – PolyGeo Nov 16 '15 at 22:13

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.