Convert Count from GetCount to Int without using Pandas

296
2
Jump to solution
03-06-2024 10:29 AM
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Based on the code below how can I store the resultant value from GetCount in a numeric datatype? When I try the `int` function I  get the following error:

 

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

 

 

Code:

 

import arcpy
arcpy.env.workspace = "C:/data/data.gdb"
Count = arcpy.management.GetCount("roads")
Count = int(Count)

 

Question | Analyze | Visualize
Tags (2)
1 Solution

Accepted Solutions
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Never mind, the following fixes it by adding getOutput(0)

 

 

 

import arcpy
arcpy.env.workspace = "C:/data/data.gdb"
Count = int(arcpy.management.GetCount("roads").getOutput(0)) 

 

 

 

This post helped:

How to determine number of records using arcpy.da.SearchCursor

Question | Analyze | Visualize

View solution in original post

2 Replies
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Never mind, the following fixes it by adding getOutput(0)

 

 

 

import arcpy
arcpy.env.workspace = "C:/data/data.gdb"
Count = int(arcpy.management.GetCount("roads").getOutput(0)) 

 

 

 

This post helped:

How to determine number of records using arcpy.da.SearchCursor

Question | Analyze | Visualize
MErikReedAugusta
Occasional Contributor III

Always proving there's more than one way to skin a cat[fish]:

count = int(arcpy.management.GetCount('feature')[0])

 

If you ask for the first index on that Result object, you get the actual result/number, itself—albeit as a string (I think).  Don't quote me on the exact datatype, but I know this is the syntax I typically use, and I haven't seen any errors from it, yet.