Reputation: 2299
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
Upvotes: 1
Views: 643
Reputation: 18280
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')
Upvotes: 1
Reputation: 2921
rs
is a Python object, can you just do this?
rs = dom.select(query)
if len(rs) > 0:
for j in rs:
...do something
else:
print("resultset is empty")
Upvotes: 0