I am having a trouble in running the following scripts:
import arcpy
arcpy.env.workspace = r'C:\MyData\my_geodatabase.gdb'
max = 123
min = 0
mean_s = 12.3
expression1 = "test(!mydensity!)"
codeblock1 = """def test(value):
if value <(%mean_s% + %min%)/2: # if value <(12.3 + 0)/2:
return "cat1"
elif value < (%max% + %mean_s%)/2 and value >=(%min% + %mean_s%)/2: #elif value < (123 + 12.3)/2 and value >=(12.3+ 0)/2:
return "cat2"
"""
a ="a"
b = "b"
arcpy.CalculateField_management(a, b,expression1,"PYTHON", codeblock1)
this python script returns with error : arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 2) Failed to execute (CalculateField).
but the python works if I did the change in the code indicated after the (# ...)in the code above(in other words,if I change those %mean%,%max%,%min% to the real numbers, it works)
I guess it is because the codeblock in python wont recognize the max min mean_s defined at the beginning or something else goes wrong?