How can I check to see if the result set is empty when querying SimpleDB in Boto 2? Can I check it before it goes into the for loop?
rs = dom.select(query)
for j in rs:
...do something
The ResultSet returned is an iterator. You can check whether it has any value with next()
which fetches the first element from the cursor if there are any. If it is empty, it raises StopIteration
error.
rs = dom.select(query)
try:
rs.next()
except StopIteration:
print('Empty ResultSet')