I am implementing a small command line tool in python that needs to ask the user a couple of questions. I use
raw_input('Are you male or female?')
all the time. Now I would like to be able to deal with dumb users (or those too lazy to read/remember the documentation), so I need to check whether the answer makes sense.
gender = ''
while gender not in ['male', 'female']:
gender = raw_input('Are you male or female?')
I am wondering whether there exists something like argparse that would automate this problem, something like
import inputparse
gender = inputparse.get_input(prompt='Are you male or female?', type=str, possible_input=['male', 'female'])
and would take care of automatic checking etc.?