I'm looping through a raster list, to export cell counts (from "Count" field in the table) to a text file, I'm only interested in cases where the field "Value" = 1, so I have included this in my search cursor (inR is from the raster list):
Rows = arcpy.SearchCursor(inR, '"Value" = 1', "", "", "")
However, some rasters in the list do not have value = 1 in the table, in this case, I want to return 0 for this count. I've tried to include this in the following loop through the search cursor
for row in Rows: countR = row.getValue('Count') if "countR" not in locals(): countR = 0 #append count to list to export later value_list.append(countR) del(countR)
When the search cursor is "empty", the get.Value line does not return any value and the object is not created, however, the following line does not work, the idea is that if countR does not exist, then it will be given the value of 0 for this raster in the list (inR).
Edit: this is where I went wrong, the above is not correct, when the search cursor is empty (like an empty list) , there is no loop and none of the statements within that loop take place.
Any help would be appreciated, or alternatives. Thanks