我正在学习如何在 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)
to
txtshow.insert(0, "{username} {surname}".format(**show)
Look here https://pyformat.info更深入地了解字符串格式。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)