def RetryQuestion(question_text, output_re='', default_val=None):
 while True:
  if (default_val is not None):
   new_text = ('%s [%s]: ' % (question_text, default_val))
  else:
   new_text = ('%s: ' % question_text)
  output = (raw_input(new_text) or str(default_val))
  output = output.strip()
  if ((not output_re) or re.match(output_re, output)):
   break
  else:
   print ('Invalid input, must match %s' % output_re)
 return output

def RetryQuestion ( question_text , output_re = '' , default_val = None ) : while True : if ( default_val is not None ) : new_text = ( '%s [%s]: ' % ( question_text , default_val ) ) else : new_text = ( '%s: ' % question_text ) output = ( raw_input ( new_text ) or str ( default_val ) ) output = output . strip ( ) if ( ( not output_re ) or re . match ( output_re , output ) ) : break else : print ( 'Invalid input, must match %s' % output_re ) return output
continually ask a question until the output_re is matched .