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
1 Answer 1
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 tox/100.0
Paul– Paul2015年11月16日 20:55:30 +00:00Commented Nov 16, 2015 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– FelixTX832015年11月16日 21:36:23 +00:00Commented Nov 16, 2015 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– FelixTX832015年11月16日 21:37:53 +00:00Commented Nov 16, 2015 at 21:37
-
Explore related questions
See similar questions with these tags.
!field_name!
. In your current method, they are not in scope.