3

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?

4

1 回答 1

3

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

换行

txtshow.insert(0, show)

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

在这里寻找更深入的字符串格式。

于 2017-05-29T10:03:50.860 回答