(ArcGIS Desktop 10.0 Python 2.7)
I need to check if any empty fields exist in featureclass fields in a gdb. These could be NONE, NULL "". The field name here is "Stand".
The following code doesn´t seem to work as "Test" is printed for every feature class even when they are filled!
rows = arcpy.SearchCursor(fc,"","","","") for row in rows: try: #check to see if field "Stand" has empty rows and print message to confirm if row.Stand: print "empty row!" break except: print "Feld existiert nicht"
Best Answer
I just wanted to point out that just using
if not row.Stand
may yield undesired results (remember, explicit is better than implicit from the Zen of Python). Take the following example:We can see here that a single space returns true, because it is a character. We are also removing zeros (which may or may not be a "NULL" value, depends on the situation).
Instead, it may be better to test if it
is None
or if the string contains any non-whitespace characters:Now we have removed any values that are just white space. This may not be a big issue, but me having prior work experience in an assessors office, there were plenty of parcel fields that were supposed to have values and only contained white space would not be flagged in the simple
if not row.Field
example. Here is what you can use to test for a single field:Or, if you want to test all fields:
This yielded: