python - 从 TinyDB 列出文档 ID
问题描述
我正在尝试在 main.py 的第 40 行从这个 github (https://github.com/syntaxsmurf/todo/blob/main/main.py)列出 db.json的内容
特别是这一行
for item in db:
table.add_row( item["task"], item["completed_by"], item["status"]) #need to find the right command for pulling data out of tinyDB into these example strings
如您所见,我可以很好地拉出并列出我在 Fx 上使用 item["task] 定义名称的项目
如果你不想看 github,这里有一个来自 db.json 的示例条目。
{
"_default": {
"1": {
"completed_by": "Today",
"status": "Pending",
"task": "Shopping"
}
}
现在我缺少的是如何提取默认生成的 ID“1”并列出它?我想用它来让用户以后可以删除它。
谢谢,我希望这个问题是有道理的!
解决方案
来自 reddit 用户 azzal07:item.doc_id 将是正确的实现。
for item in db:
table.add_row(str(item.doc_id), item["task"], item["completed_by"], item["status"])
Str() 用于丰富的表函数,如果它看起来是一个 int,它就不起作用。
推荐阅读
- tosca - 加快“如果”条件(验证/等待)
- javascript - 不变违规:requireNativeComponent:“BVLinearGradient”
- javascript - Mailgun 帐户在提交到 GitHub 后停用
- string - 如何键入包含少于 5 个字符的字符串并仍然继续下一行代码?
- bash - watch 命令不适用于特殊字符和引号
- angular - Angular 2+缓存的HTTP请求强制重新加载
- linux - 为什么在我的 fuse 文件系统中使用 ls 命令时会出现输入/输出错误?
- javascript - 删除 JavaScript 中的一些元素
- reactjs - 返回值并打印
零件 - deep-learning - 困惑:CNN的图像标记用于训练的目的是什么?