The following code isn't working as expected and I'm not sure why:
UpOrDown = reclass(!UpOrDown!)
def reclass (Z,GP):
if (GP == "DT" and Z == "CG"):
UpOrDown = 1
if (GP == "DT" and Z == "CN"):
UpOrDown = 1
if (GP == ...and so on.... )
The expression is passing as valid but the wrning (warning 002858) suggests that there is a TypeError
in reclass()
which is missing the argument 'G'
.
I have added this into the code at UpOrDown = reclass(!UpOrDown!,!G!)
which returns no error but doesn't output the expected variable of 1 in the UpOrDown
column (which is Double).
I also changed the dependent variables to both Z and GP which still didn't change anything.
What is missing?
1 Answer 1
The field calculator needs to return
a value that will be populated onto your field. Your current code just sets a variable UpOrDown
, it doesn't tell the calculator what to write.
Additionally you should use elif
rather than if
for your subsequent lines so that the parser only processes what it needs to, and then finish up with an else
to handle what happens if none of the if
/elif
do anything.
reclass(!Parcels_Zoning_Interest_ZONINGABBREV!, !GPABBREVIATION!)
def reclass (Z,GP):
if (GP == "DT" and Z == "CG"):
UpOrDown = 1
elif (GP == "DT" and Z == "CN"):
UpOrDown = 2
elif (GP == "this" and Z == "that" ):
UpOrDown = 3
else:
UpOrDown = 0
return UpOrDown
Explore related questions
See similar questions with these tags.
reclass(!UpOrDown!)
and two in the arglistdef reclass (Z,GP)
and you don't show what is returned. Look again at the documentation. 1) same number of arguments, 2)return
a singleton valuereturn UpOrDown
.elif
in your conditional logic (orreturn 1
instead of not returning the set variable)