gpt4 book ai didi

python-3.x - 如何从 TinyDB 数据库中检索单个值?

转载 作者:行者123 更新时间:2023-12-01 13:34:57 28 4
gpt4 key购买 nike

我正在学习如何在 Python 上使用 TinyDB,我已经掌握了基础知识(添加、删除、更新等)。但现在我正在尝试从数据库中检索特定值。我正在使用的代码是在这个方法中:

def showpassword():
show = userdb.get(where("username") == txtname.get())
txtshow.insert(0, show)

当我运行该方法时,它显示如下输出:

{'username': 'John', 'surname': 'Doe'}

如何才能让我只显示用户的名字或姓氏而不显示任何括号?

最佳答案

TinyDb 将其数据存储为 JSON,在 Python 中表示为字典。

换行

txtshow.insert(0, show)

txtshow.insert(0, "{username} {surname}".format(**show)

here深入了解字符串格式。

关于python-3.x - 如何从 TinyDB 数据库中检索单个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44239574/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com