I am counting the number of features in a geodabase. I am triying to insert the feature name and the count inside a dbf table which has only two fields: "FEAT" (Text field which containts the feature name) and "COUNT" (short field which contains the feature count).

This is my code:

  listlayers= arcpy.ListFeatureClasses()        
  for feat in listlayers:
    count = 0
    count = arcpy.GetCount_management(feat)
    feat = str(feat)
    if count > 0:
      print feat + " has " + str(count) + " entries"
      with arcpy.da.InsertCursor(destinationgeneraltable, ("FEAT","COUNT")) as icursor:
      print feat + " is void"

I use an insert cursor to insert these records inside this table but it fails without any error message.

  • What does your destination DBF file look like after this? – Andy Bradford Mar 11 '16 at 15:11
  • Thanks radouxju the dbf is void an blocked, It has a block file. – Paulus Mar 11 '16 at 15:14
  • Create cursor outside loop Make sure. Dbf. Is short – FelixIP Mar 11 '16 at 19:58

getCount returns an object, not an integer. You need to use :

count = int(arcpy.GetCount_management(lyrfile).getOutput(0))

then I would not use feat = str(feat)

  • Thansk radouxju it is working. – Paulus Mar 11 '16 at 15:17

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.