How would I check if a filtered request returns an empty array?
How would I check if a filtered request returns an empty array?
I started Javascript around a year and a half ago but I started Python around a week ago so I'm still a beginner at this. So I'm trying to figure out if a user is already stored into the users table and if they aren't then it will add them to it and if they are then it skips.
import rethinkdb as r
r.db('bot').table('users').filter(r.row["id"] == "253544423110082589").run()
this code should return
<rethinkdb.net.DefaultCursor object at 0x03DAAE10> (done streaming):
[
]
So how exactly would I check if its empty?
I tried something like
if not r.db('bot').table('users').filter(r.row["id"] == "253544423110082589").run():
# add user to table
else:
continue
but it continues even when the user isn't in the table. So please tell me what I'm doing wrong and how I can actually get it to work
1 Answer
1
I'm not familiar with the library you're using, but you may be able to check the length of the table.
It might look something like this:
if len(table) == 0:
# add user to table
else:
continue
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.