列出TinyDB中的文档ID

2024-10-01 04:55:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在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”并列出它?我想用它来帮助用户以后删除它

谢谢,我希望这个问题有意义


Tags: pyhttpsgithubcomjsonfortaskdb
1条回答
网友
1楼 · 发布于 2024-10-01 04:55:21

来自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,则它不起作用

相关问题 更多 >