Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to get a number by counting how many points are in a shapefile. And this works (I think), except I then am running into trouble using that number somewhere else. Eventually, I'll be using that count in some math (field calculator), but while debugging I'm running into an error that will end up causing me trouble later on. This code:

TotalPoints = arcpy.GetCount_management(Path_Pts)
arcpy.AddMessage(">>>> PROCESS: COUNT PATH POINTS {" + TotalPoints + "}")

gives this error:

TypeError: cannot concatenate 'str' and 'Result' objects

I tried casting it as a int, which it ALSO doesn't like:

TypeError: int() argument must be a string or a number, not 'Result'

So I've got a 'Result' object and need to turn it into a number. How can I do that -- or is using the arcpy function unnecessary or overly complicated here? (I'm learning arcpy and python as I go.)

share|improve this question

1 Answer 1

up vote 13 down vote accepted

Use the following method on the Result object and you'll be able to cast as int:

.getOutput(0) will return the value at the first index position of a tool.

int(arcpy.GetCount_management(Path_Pts).getOutput(0))

share|improve this answer
3  
I would at that yo may want to wrap this in a try accept because if it fails it will throw an exception and stop the process. –  Jamie Mar 22 '13 at 20:02
    
YES, that works great. Thanks! –  Erica Mar 23 '13 at 0:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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