I want to take all positive values in a field and multiply them by -1000. To do this, I put together the following code block:
def myCalc(x):
if (x > 0):
x*(-1000)
return x
else:
return x
and then I call the expression:
myCalc( !FieldName! )
However, when I execute this field calculation, I get no warnings or errors, but the values in my field also don't change. The numbers look like this (before and after the calculation):
What is wrong with my code?
1 Answer 1
You need to reassign x to your calculation:
def myCalc(x):
if (x > 0):
x = x*(-1000)
return x
else:
return x
If you'd like to save some typing you can simplify your logic a little:
def myCalc(x):
if (x > 0):
x = x*(-1000)
return x
-
Thanks! It's been a while since I had to do logic like this. It's always the little things that I miss. :DStella– Stella2017年09月18日 18:49:37 +00:00Commented Sep 18, 2017 at 18:49
Explore related questions
See similar questions with these tags.