recipes.query_yes_no

recipes.query_yes_no(question, default=None)[source]

Ask a yes/no question via raw_input() and return the answer.

Parameters:

question : str

The question to be printed in the prompt

default : str

The presumed answer that is used in case the <Return> key is pressed (must be either “yes” or “no”). If default is None then a definitive answer is required (pressing <Return> will re-print question in the prompt)

Returns:

answer : bool

Either True if the input was “yes”/”y” or False otherwise.

See also

ActiveState
ActiveState Code Recipe #577058 currently available here

Notes

This code is a slightly modified version of recipe no. 577058 from ActiveState written by Trent Mick.