How to get one value from TinyDB database?

I am learning how to use TinyDB in Python and I have the basics working (add, remove, update, etc.). But now I am trying to get certain 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 outputs output like this:

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

      

How can I get it so that I can only display the user's first or last name and without any parentheses?

+3


source to share


1 answer


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

Change the line

txtshow.insert(0, show)

      



to

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

      

Take a look here for a deeper dive into string formatting.

+3


source







All Articles