I'm trying to calculate a total demand in ArcGIS 10.2.2, stored in fields Demand1, Demand2, ... , Demand20. Some of them contain a numeric value. The others have a <Null>
value. The sum therefore always returns <Null>
.
I've tried in Python to define, in the pre-script a function:
def D(a):
0 if a else 1
(as recommended in Field calculator if and elseif statement with <Null> values in ArcGis 10.1, with correct indents, etc.)
then in the code
D( !Demand1! ) + D( !Demand2! ) + ... + D( !Demand3! )
It cannot compute. Do you have any suggestions?
1 Answer 1
If you're defining a function, you need to use a return
statement within it for D()
to actually return a value. Use return 0 if a else 1
.
-
Thanks for your help! The return saved everything, but was more likely 'return a is a else 0' and that way it works.Baptiste Verniest– Baptiste Verniest2016年02月18日 09:13:53 +00:00Commented Feb 18, 2016 at 9:13
Explore related questions
See similar questions with these tags.