如何从TinyDB数据库中检索单个值?

时间:2017-05-29 09:55:49

标签: python-3.x tkinter tinydb

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

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

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

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

我怎样才能获得它,以便我只能显示用户的姓名或姓氏,而不显示任何括号?

1 个答案:

答案 0 :(得分:3)

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

更改行

txtshow.insert(0, show)

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

查看here以深入了解字符串格式。

相关问题