0

I am able to get the count of rows in Feature Class wing Python Window like

arcpy.GetCount_management("pipe")

which is properly returning the number of rows inside the pipe feature class. but in a stand alone environment by using this code

import arcpy
from arcpy import env
env.workspace = "C:/Users/auser/Documents/ArcGIS/Projects/Electric/Electric.gdb"
count = arcpy.GetCount_management("pipe")
print(count)

I am always getting 0 in result back

I also tried

import arcpy
from arcpy import env
env.workspace = "C:/Users/auser/Documents/ArcGIS/Projects/Electric/Electric.gdb/dataset"
count = arcpy.GetCount_management("pipe")
print(count)

By adding the dataset to the env.workspace and again I am getting the same 0 back! Can you please let me know what I am doing wrong?

Hornbydd
44.9k5 gold badges42 silver badges84 bronze badges
asked Aug 20, 2021 at 7:27
5
  • 4
    It should work. Have you tried print(count.getOutput(0)) Commented Aug 20, 2021 at 7:33
  • 4
    Is pipe in a FeatureDataset? Commented Aug 20, 2021 at 9:46
  • 2
    Is dataset a feature dataset Commented Aug 20, 2021 at 10:32
  • Do you get expected count when the feature dataset is named something other than "dataset" (which may be a reserved word)? Commented Aug 20, 2021 at 18:53
  • Set environment extent to union of inputs and it will work arcpy.env.extent = "MAXOF". Alternative is doing this in environment settings in ArcCatalog. Commented Aug 20, 2021 at 22:09

1 Answer 1

0

You need to access the result of the GetCount tool - https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/get-count.htm

count = arcpy.GetCount_management("pipe").getOutput(0))
answered Aug 24, 2021 at 8:00

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.