1
from tinydb import TinyDB, Query
db = TinyDB('db.json')
ddd = Query()
kl = free
output = db.search(ddd.state == 'free')
如何在tinydb db.search中使用變量k1?如何在python中的tinydb查詢中包含變量?
from tinydb import TinyDB, Query
db = TinyDB('db.json')
ddd = Query()
kl = free
output = db.search(ddd.state == 'free')
如何在tinydb db.search中使用變量k1?如何在python中的tinydb查詢中包含變量?
只是用它在db.search
from tinydb import TinyDB, Query
db = TinyDB('db.json')
ddd = Query()
db.insert({'state': 'free', 'field': 1})
db.insert({'state': 'n', 'field': 2})
db.insert({'state': 'free', 'field': 3})
kl = 'free'
output = db.search(ddd.state == kl)
print(output)
輸出
[{'state': 'free', 'field': 1}, {'state': 'free', 'field': 3}]
謝謝! ..你能讓我知道如何列出列表或列格式的輸出? – Zeal