我大约一年半以前开始使用Javascript,但是大约一周前我开始使用Python,所以我在这方面还是个初学者。因此,我正在尝试确定用户是否已经存储到users表中,如果没有,则将其添加到表中,如果是,则跳过。
import rethinkdb as r
r.db('bot').table('users').filter(r.row["id"] == "253544423110082589").run()
此代码应返回
<rethinkdb.net.DefaultCursor object at 0x03DAAE10> (done streaming):
[
]
那么我该如何检查它是否为空呢?
我试过这样的东西
if not r.db('bot').table('users').filter(r.row["id"] == "253544423110082589").run():
# add user to table
else:
continue
但是,即使用户不在表中,它也会继续。所以,请告诉我我做错了什么,以及我如何才能真正让它工作
发布于 2018-07-30 08:12:21
发布于 2018-07-30 08:02:09
我不熟悉您正在使用的库,但是您可以检查一下表的长度。
它可能看起来像这样:
if len(table) == 0:
# add user to table
else:
continue
https://stackoverflow.com/questions/51585492
复制相似问题