I am trying to achieve print all featureclass, total count, notNullvalues. I am trying hard on this code.

but getting Error:

suggest how can I code better and working. I am not regular python user.

RuntimeError: ERROR 999999: Error executing function.

import arcpy
import arcpy
import collections

arcpy.env.workspace = r"path"
arcpy.env.overwriteOutput = True


#StartTime = time.clock()

fclist = arcpy.ListFeatureClasses("*Rebok*")
for fc in fclist:

   fields = [f.name for f in arcpy.ListFields(fc)]

   Tcount = str(arcpy.GetCount_management(fc))

# Loop through Table and see which fields are NOT NULL or Non Blank
   cur = arcpy.SearchCursor(fc)
   count = 0
   for row in cur:
    if not row.getValue(fields) in [None, " ", ""]:
            count += 1
   print count
  • 2
    arcpy.GetCount_management takes Layer or View as argument, not FeatureClass. row.getValue takes single field as argument, not list. – Serge Norin Sep 14 '17 at 6:17
  • @SergeNorin I am using FGDB that has multiple FCs with lots of fields(different data type) some field contains "", " ", NULL. so that I am trying this method. I am skeptical about Getcount management with what SQL will Suit. – GIS Data Butcher Sep 14 '17 at 6:22
  • What is the full error message, including line number, that you receive when you run precisely the code that you have presented? – PolyGeo Sep 14 '17 at 6:33
  • @GISDataButcher you can use FGDB, shapefile or whatsoever, but GetCount works with Layer object. Run MakeFeatureLayer_mamagement first with your FC as input If you want to use it. And fields. Replace if not row.getValue(fields) in [None, " ", ""]: with if not set([row.getValue(f) for f in fields]).intersection(set[None, '', ' ']): – Serge Norin Sep 14 '17 at 6:46

To get a count of null values, use the where argument for GetCount, e.g.

arcpy.MakeFeatureLayer_management("MyFeatureclass", "test_lyr", r"Fieldname is null")
print arcpy.GetCount_management("test_lyr")

If you need to test for other 'empty' values too, change the where argument to Fieldname is null OR Fieldname in ('', ' ') etcetera.

In general this will be faster than using a cursor.

  • Getting this Error ExecuteError: ERROR 000358: Invalid expression OBJECTID is null OR OBJECTID in ('', ' ') Failed to execute (MakeFeatureLayer). ..I thing it caused due to multiple data type in multiple fields. for Example the above one fails because it is numeric type. (taken objectid as example, have others numeric fields too) – GIS Data Butcher Sep 15 '17 at 5:37
  • Of course, objectid is a numeric field, so it can never be '' or ' ' (a string). Moreover, I don't think the objectid field can ever be empty, so why check for that? – Berend Sep 15 '17 at 6:46
  • Okay. this was good. I skipped Objectid in Loop for that matter. But How do I do for numeric fields? – GIS Data Butcher Oct 9 '17 at 6:39
  • The same, but without single quotes. E.g. "FieldName is null" to check for an empty value or, "FieldName = 0" to check for a value of zero, if that's what you want. – Berend Oct 9 '17 at 10:27

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.