pythongoogle-app-enginegqlgqlquery

Zero results in Query/GqlQuery


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?


Solution

  • 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