def ask_number(question, match=None, review=None): return get_answer(question, qa_helpers.match_prompt(match, int, "Enter Number %s", 'Enter Number'), conv_fn=qa_helpers.to_number, test=match, review=review)
def ask_select_n(question, alternatives, review=None): r''' >>> from StringIO import StringIO >>> sys.stdin = StringIO('1,3\n') >>> ask_select_n(u'which one?', ... (('a', u'first one'), ('b', u'second one'), ... ('c', u'third one'))) ______________________________________________________________________________ which one? 1. first one 2. second one 3. third one ? [1-3, ...] ('a', 'c') ''' match = slice(1, len(alternatives)) question += u''.join(u'\n%3d. %s' % (i + 1, u'\n '.join(text.split('\n'))) for i, (tag, text) in enumerate(alternatives)) i_tuple = get_answer(question, qa_helpers.match_prompt(match, int, u"\n? [%s, ...]"), conv_fn=lambda str: qa_helpers.to_tuple(str, conv_fn=qa_helpers.to_int, test=match), review=review) return tuple(alternatives[i-1][0] for i in i_tuple)
def ask_float(question, match=None, review=None): return get_answer( question, qa_helpers.match_prompt(match, float, "Enter Number %s", "Enter Number"), conv_fn=qa_helpers.to_float, test=match, review=review, )
def ask_integer(question, match=None, review=None): return get_answer( question, qa_helpers.match_prompt(match, int, "Enter Integer %s", "Enter Integer"), conv_fn=qa_helpers.to_int, test=match, review=review, )
def ask_string(question, match=None, review=None): r''' >>> from StringIO import StringIO >>> sys.stdin = StringIO('yes\n') >>> ask_string(u'enter string?') ______________________________________________________________________________ enter string? u'yes' ''' return get_answer(question, qa_helpers.match_prompt(match, str, u"[%s]", u''), test=match, review=review)
def ask_number(question, match=None, review=None): r''' >>> from StringIO import StringIO >>> sys.stdin = StringIO('4\n') >>> ask_number(u'enter number?') ______________________________________________________________________________ enter number? (number) 4 ''' return get_answer(question, qa_helpers.match_prompt(match, int, u"[%s]", u'(number)'), conv_fn=qa_helpers.to_number, test=match, review=review)
def ask_float(question, match=None, review=None): r''' >>> from io import StringIO >>> sys.stdin = StringIO('4\n') >>> ask_float('enter number?') ______________________________________________________________________________ enter number? (float) 4.0 ''' return get_answer(question, qa_helpers.match_prompt(match, float, "[%s]", '(float)'), conv_fn=qa_helpers.to_float, test=match, review=review)
def ask_select_1(question, alternatives, review=None): r''' >>> from io import StringIO >>> sys.stdin = StringIO('2\n') >>> ask_select_1('which one?', ... (('a', 'first one'), ('b', 'second one'), ... ('c', 'third one'))) ______________________________________________________________________________ which one? 1. first one 2. second one 3. third one ? [1-3] 'b' ''' match = slice(1, len(alternatives)) question += ''.join('\n%3d. %s' % (i + 1, '\n '.join(text.split('\n'))) for i, (tag, text) in enumerate(alternatives)) i = get_answer(question, qa_helpers.match_prompt(match, int, "\n? [%s]"), conv_fn=qa_helpers.to_int, test=match, review=review) return alternatives[i - 1][0]
def ask_string(question, match=None, review=None): return get_answer(question, qa_helpers.match_prompt(match, str, "Enter %s", 'User Question'), test=match, review=review)