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

编程入门 行业动态 更新时间:2024-10-25 02:22:56
本文介绍了如何从 TinyDB 数据库中检索单个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I'm learning how to use TinyDB on Python and I have the basics working (add, remove, update etc.). But now I'm trying to retrieve specific values from the database. The code I'm using is in this method:

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

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

When I run the method, it displays the output as follows:

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

如何才能只显示用户名或姓氏,不带任何括号?

How can I get it so that I can display only the user's name or surname and without any brackets?

推荐答案

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

TinyDb stores its data as JSON which is represented in Python as a dictionary.

换行

txtshow.insert(0, show)

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

查看此处,深入了解字符串格式.

Look here for a deeper dive in to string formatting.

这篇关于如何从 TinyDB 数据库中检索单个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 06:49:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390758.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   TinyDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!