-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py~
39 lines (33 loc) · 1.1 KB
/
helper.py~
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
38
39
def generate_ui(functions, input_prompt, again_prompt):
conn = sqlite3.connect(database)
again = 'y'
while again == 'y':
show_options(functions.keys())
user_input = input(input_prompt)
while user_input != 'q':
if is_integer(user_input) and int(user_input) in range(
1, len(functions)+1):
list(functions.values())[int(user_input)-1](conn)
break
else:
print('Invalid selection: Enter a number from 1 to %i' %
len(functions))
user_input = input()
if user_input == 'q':
break
again = input(again_prompt)
def show_options(options):
for number, option in enumerate(options):
print('%i. %s' % (number+1, option))
def print_records(cursor):
print('-'*80)
for record in cursor:
for i, value in enumerate(record):
print('%s: %s' % (cursor.description[i][0], value))
print('-'*80)
def is_integer(s):
try:
int(s)
return True
except ValueError:
return False