how to check if cursor object is empty?

35794
20
02-02-2012 06:15 AM
kyleturner
New Contributor III
It seems an easy task, but I can't figure out how to check if the searchcursor object is empty.
I know that it is empty because the query fails....i.e. arcpy.searchcursor(FC, query).
However, even if it (arcpy.searchcursor..) fails, it still returns a geoprocessing cursor object...

rows = gp.SearchCursor(crosswalk_dbf,query)

print rows ---> returns
<geoprocessing cursor object object at 0x029C7CC0>


I can't check if it's empty, because, well, it's not.
And for reasons I obviously don't understand.......

rows = gp.SearchCursor(crosswalk_dbf,query)
for row in rows:
  if not row.isNull(fieldname)

------------

is always 'true'.

Please help.

I'm using Arc10 SP3, win 7 64bit.

Many thanks.
Tags (2)
0 Kudos
20 Replies
BlakeTerhune
MVP Regular Contributor

I agree that I wasn't too keen on having to "consume the iterable" and reset it. I had tried the .next() approach and got the StopIteration error but wasn't quite sure how to handle it; thank you Bruce Harold‌ for mentioning that. That last option with row = None is clever and seems to solve both problems; thanks for sharing.

0 Kudos