Using an arcpy script how do I get the feature attribute count per feature class in a fileGDB? Ideally I would like to output to a spreadsheet, with the feature class name in one column and the attribute count in another.

  • by "feature attribute count" do you mean a count of how many features there are, or a count of how many attributes (fields?) a feature has? – mr.adam Jul 9 '15 at 19:23
  • The number of attributes per feature class in a fileGDB. – ionicdez Jul 9 '15 at 19:35

Use this function to return all of the feature classes in the GDB:

def listFcsInGDB():
    for fds in arcpy.ListDatasets('','feature') + ['']:
        for fc in arcpy.ListFeatureClasses('','',fds):
            yield os.path.join(arcpy.env.workspace, fds, fc)

Now loop over that function to work with each individual feature class:

arcpy.env.workspace = "C:\\gdb"
for fc in listFcsInGDB():
    print fc
    print arcpy.GetCount_management(fc) <-- number of rows
    print len(arcpy.ListFields(fc)) <-- number of columns

I've left the part about writing to a spreadsheet up to you.

Note, I haven't tested this so feel free to correct me if I made any mistakes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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