0

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):

enter image description here

What is wrong with my code?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 18, 2017 at 18:03

1 Answer 1

2

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
answered Sep 18, 2017 at 18:06
1
  • Thanks! It's been a while since I had to do logic like this. It's always the little things that I miss. :D Commented Sep 18, 2017 at 18:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.