MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / ask_question

Method ask_question

python/example_code/glue/question.py:46–64  ·  view source on GitHub ↗

Asks a single question and validates it against a list of validators. When an answer fails validation, the complaint is printed and the question is asked again. :param question: The question to ask. :param validators: The list of validators that the answer m

(question, *validators)

Source from the content-addressed store, hash-verified

44
45 @staticmethod
46 def ask_question(question, *validators):
47 """
48 Asks a single question and validates it against a list of validators.
49 When an answer fails validation, the complaint is printed and the question
50 is asked again.
51
52 :param question: The question to ask.
53 :param validators: The list of validators that the answer must pass.
54 :return: The answer, converted to its final form by the validators.
55 """
56 answer = None
57 while answer is None:
58 answer = input(question)
59 for validator in validators:
60 answer, complaint = validator(answer)
61 if answer is None:
62 print(complaint)
63 break
64 return answer
65
66 @staticmethod
67 def non_empty(answer):

Callers 2

runMethod · 0.45
ask_questionsMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected