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?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
RedCode
  • 363
  • 1
  • 6
  • 23

1 Answers1

3

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)

Look here for a deeper dive in to string formatting.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Colwin
  • 2,655
  • 3
  • 25
  • 25