2

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:
         icursor.insertRow((feat,count))
    else:
      print feat + " is void"

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

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

1 Answer 1

4

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)

1
  • Thansk radouxju it is working.
    – Paulus
    Commented Mar 11, 2016 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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