MCPcopy Create free account
hub / github.com/WebAssembly/wabt / YesNoPrompt

Function YesNoPrompt

test/run-tests.py:826–855  ·  view source on GitHub ↗

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')

Source from the content-addressed store, hash-verified

824
825# Source : http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input
826def 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
858def RunMultiThreaded(infos_to_run, status, options, variables):

Callers 1

RunSingleThreadedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected