python - Why looping Tinydb.update work just for the first time in loop
问题描述
actual version of tinydb 4.3.0
from tinydb import TinyDB, Query
db = TinyDB('db.json')
dbtable = db.table('Counters')
Search = Query()
splitemsg = ['', 'nwm', '', 'nwm', '', 'nwm', ''] #in other cases it can be different
for tableval in dbtable.all():
for i in splitemsg:
if i == counterfilt:
dbtable.update({'Value': tableval['Value'] + 1}, Search['Counter_filter'].any(counterfilt)) #this will add 1 to the Value in the table
my json file row:
{"_default": {}, "Counters": {"1": {"Counter_name": "nwm", "Counter_filter": ["nwm", "nvm"], "Value": 0}}}
After this it is supposed to add 3 to the value in my table in tinydb, but it just add 1, why it's not working? I tried some sleep inside loop, didn't work. I tried other versions of tinydb, didn't work. I would have another solution for this if I can split the string, but separator is variable and I need the separator to be keeped.
解决方案
推荐阅读
- python - 通过 Selenium 和 Webdriver 遍历 find_element_by_xpath() 的元素列表
- android - kotlin 中的 flatMap()
- android - 微调器默认选择为“选择您的项目”
- php - 如何从php返回json数据
- excel - 字典和函数:未定义用户定义类型
- javascript - 如何查找从服务器运行或不使用 javascript 的 html 文件?
- c# - 如何响应不同线程上的事件
- python - 将标识符行添加到数据框,然后写入 excel 文件
- python - 使用烧瓶将字符串中的文本替换为图像
- python-3.x - Python:如何存储相互重叠的2个声音文件