python - Filter out if query returns nothing -


how can filter out results database can store data returns something.

i got following code:

mergedlist_uniques = [id1,id2,id3,id4,..] #list containing data  in range(0, 5):     cur = db.cursor()     cur.execute("select id `id_activities` `id_activities`.`id` = '" + mergedlist_uniques[i] + "' limit 1")     results = cur.fetchall()     if results != "":         print("empty, result is: ", results)         #data.append(results) 

in if statement check whether results contains nothing not working.

i still following result:

>>> ('empty, result is: ', ()) 

what should expect whenever result is: () should not print if contains:

>>> ('empty, result is: ', (idx)) 

then should print out result.

what did wrong?

as per python documentation, none, 0, "", (), {}, [] treated false, use

if results:     #do 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -