forked from ruiyuanlu/CommonScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellChoose.py
More file actions
25 lines (22 loc) · 703 Bytes
/
Copy pathshellChoose.py
File metadata and controls
25 lines (22 loc) · 703 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
# @author Alu
from sys import argv
def make_choice(question_str, options=["Yy", "Nn"], default='', end='\n'):
"""
return valid or not, and the input
(True, input): input valid
(False, input): input invalid
"""
option_str = "|".join(options)
if isinstance(default, str) and len(default) > 0:
default_choice = '(default: %s)' % default
else :
default_choice = ''
choice = input('%s [%s] %s:' % (question_str, option_str, default_choice))
if len(default) > 0 and choice == '':
return True, default
# if is valid choice
valid = False
for op in options:
if choice in op:
valid = True
return valid , choice