MCPcopy Create free account
hub / github.com/ExpressLRS/ExpressLRS / query_yes_no

Function query_yes_no

src/python/query_yes_no.py:5–25  ·  view source on GitHub ↗

Ask a yes/no question via raw_input() and return their answer. "question" is a string that is presented to the user. The "answer" return value is True for "yes" or False for "no".

(question='')

Source from the content-addressed store, hash-verified

3
4
5def query_yes_no(question='') -> bool: #https://code.activestate.com/recipes/577058/
6 """Ask a yes/no question via raw_input() and return their answer.
7 "question" is a string that is presented to the user.
8 The "answer" return value is True for "yes" or False for "no".
9 """
10 # Always return false if not in an interactive shell
11 if not sys.stdin.isatty():
12 return False
13
14 valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
15
16 while True:
17 choice = ''
18 try:
19 choice = inputimeout(prompt=question, timeout=5)
20 except TimeoutOccurred:
21 sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n')")
22 sys.stdout.flush()
23
24 if choice in valid:
25 return valid[choice]

Callers 1

reset_to_bootloaderFunction · 0.90

Calls 2

writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected