Advertisement
Guest User

kvdb.py

a guest
Feb 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. db = {}
  2. print('Welcome to the simplest key-value database')
  3. while True:
  4.     print('What do you want to do?')
  5.     print('Enter P to [P]ut, G to [G]et or L to [L]ist')
  6.     print('Or enter Q to [Q]uit')
  7.     action = raw_input()
  8.     if action == 'P':
  9.         k = raw_input('Enter key: ')
  10.         d = raw_input('Enter data: ')
  11.         db[k] = d
  12.     elif action == 'G':
  13.         k = raw_input('Enter key: ')
  14.         if not k in db:
  15.             print('No such key')
  16.         else:
  17.             print('Your data: %s' % db[k])
  18.     elif action == 'L':
  19.         print('DB contents:')
  20.         print(db)
  21.     elif action == 'Q':
  22.         print('Bye')
  23.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement