database - how to include a variable in tinydb query in python? -
from tinydb import tinydb, query db = tinydb('db.json') ddd = query() kl = free output = db.search(ddd.state == 'free')
how use variable k1 in tinydb db.search?
just use in 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)
output
[{'state': 'free', 'field': 1}, {'state': 'free', 'field': 3}]
Comments
Post a Comment