Ask a yes/no question via input() and return their answer. "question" is a string that is presented to the user. "default" is the presumed answer if the user just hits . It must be "yes" (the default), "no" or None (meaning an answer is required of the user). The
(question, default='yes')
| 824 | |
| 825 | # Source : http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input |
| 826 | def YesNoPrompt(question, default='yes'): |
| 827 | """Ask a yes/no question via input() and return their answer. |
| 828 | |
| 829 | "question" is a string that is presented to the user. |
| 830 | "default" is the presumed answer if the user just hits <Enter>. |
| 831 | It must be "yes" (the default), "no" or None (meaning |
| 832 | an answer is required of the user). |
| 833 | |
| 834 | The "answer" return value is True for "yes" or False for "no". |
| 835 | """ |
| 836 | valid = {'yes': True, 'y': True, 'ye': True, 'no': False, 'n': False} |
| 837 | if default is None: |
| 838 | prompt = ' [y/n] ' |
| 839 | elif default == 'yes': |
| 840 | prompt = ' [Y/n] ' |
| 841 | elif default == 'no': |
| 842 | prompt = ' [y/N] ' |
| 843 | else: |
| 844 | raise ValueError('invalid default answer: \'%s\'' % default) |
| 845 | |
| 846 | while True: |
| 847 | sys.stdout.write(question + prompt) |
| 848 | choice = input().lower() |
| 849 | if default is not None and choice == '': |
| 850 | return valid[default] |
| 851 | elif choice in valid: |
| 852 | return valid[choice] |
| 853 | else: |
| 854 | sys.stdout.write('Please respond with \'yes\' or \'no\' ' |
| 855 | '(or \'y\' or \'n\').\n') |
| 856 | |
| 857 | |
| 858 | def RunMultiThreaded(infos_to_run, status, options, variables): |