1

Is there anyway to add together GetCount Results? I am using GetCount to find the number of selected features for multiple layers but when I try to add them all together I get an error message saying it is an unsupported operand type for +: 'Result' and 'Result'.

SampledFaild = arcpy.GetCount_management('SamplingFaild')
SampledValid = arcpy.GetCount_management('SamplingValid')
Total = SampledFaild + SampledValid
0

1 Answer 1

1

As the error message indicates, the return value of GetCount_management is a Result object. The documentation for GetCount includes an example of how to extract the return value, by casting the Result.GetOutput() value to integer.

Rewriting your code to use Style Guide for Python (PEP 8) recommended leading lowercase variable names, the result is:

sampledFaild = arcpy.GetCount_management('SamplingFaild')
sampledValid = arcpy.GetCount_management('SamplingValid')
total = int(sampleFaild.getOutput(0)) + int(sampleValid.getOutput(0))
2

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.