-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpledb.py
More file actions
37 lines (32 loc) · 945 Bytes
/
Copy pathsimpledb.py
File metadata and controls
37 lines (32 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys,shelve
def store_person(db):
pid = input('Enter unique 10 number: ')
person = {}
person['name'] = input('Enter name: ')
person['age'] = input('Enter age: ')
person['phone'] = input('Enter phone: ')
db[pid] = person
def lookup_person(db):
pid = input('Enter ID nunber: ')
field = input('What would you like to know? name, age or phone')
field = field.strip().lower()
print(db[pid][field])
def enter_command():
cmd = input('Enter command for help: ')
cmd = cmd.strip().lower()
return cmd
def run():
database = shelve.open('path')
try:
while True:
cmd = enter_command()
if cmd == 'store':
store_person(database)
elif cmd == 'lookup':
lookup_person(database)
else:
assert 'Illegal command line'
finally:
database.close()
if __name__ == '__main__':
run()