def query_yes_no(question, default='yes'):
 valid = {'yes': 'yes', 'y': 'yes', 'ye': 'yes', 'no': 'no', 'n': 'no'}
 if (default is None):
  prompt = ' [y/n] '
 elif (default == 'yes'):
  prompt = ' [Y/n] '
 elif (default == 'no'):
  prompt = ' [y/N] '
 else:
  raise ValueError(("invalid default answer: '%s'" % default))
 while 1:
  sys.stdout.write((question + prompt))
  choice = raw_input().lower()
  if ((default is not None) and (choice == '')):
   return default
  elif (choice in valid.keys()):
   return valid[choice]
  else:
   sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")

def query_yes_no ( question , default = 'yes' ) : valid = { 'yes' : 'yes' , 'y' : 'yes' , 'ye' : 'yes' , 'no' : 'no' , 'n' : 'no' } if ( default is None ) : prompt = ' [y/n] ' elif ( default == 'yes' ) : prompt = ' [Y/n] ' elif ( default == 'no' ) : prompt = ' [y/N] ' else : raise ValueError ( ( "invalid default answer: '%s'" % default ) ) while 1 : sys . stdout . write ( ( question + prompt ) ) choice = raw_input ( ) . lower ( ) if ( ( default is not None ) and ( choice == '' ) ) : return default elif ( choice in valid . keys ( ) ) : return valid [ choice ] else : sys . stdout . write ( "Please respond with 'yes' or 'no' (or 'y' or 'n').\n" )
ask a yes/no question via raw_input() and return their answer .