views:

159

answers:

2

How do I know if the results of my query either using the Query interface or the GqlQuery interface returned zero results? Would using .get() on zero results produce an error? If yes, what's the best way to handle it?

+4  A: 

when doing a get() if there are no results you will have an object containing None

I normally do

result = query.get()
if result is None:
  #do the following

or if you want to check that its not none then

if result is not None:
  #do the following
AutomatedTester
+2  A: 

if a query returns no results, fetch() returns an empty list [] and get() returns None

in either case you can use the following:

if result:
    #handle the result
else:
    #no results were returned
wings