def ask_timezone(question, default, tzurl):
 lower_tz = [tz.lower() for tz in pytz.all_timezones]
 while True:
  r = ask(question, str_compat, default)
  r = r.strip().replace(u' ', u'_').lower()
  if (r in lower_tz):
   r = pytz.all_timezones[lower_tz.index(r)]
   break
  else:
   print(u'Please enter a valid time zone:\n (check [{0}])'.format(tzurl))
 return r

def ask_timezone ( question , default , tzurl ) : lower_tz = [ tz . lower ( ) for tz in pytz . all_timezones ] while True : r = ask ( question , str_compat , default ) r = r . strip ( ) . replace ( u' ' , u'_' ) . lower ( ) if ( r in lower_tz ) : r = pytz . all_timezones [ lower_tz . index ( r ) ] break else : print ( u'Please enter a valid time zone:\n (check [{0}])' . format ( tzurl ) ) return r
prompt for time zone and validate input .