date - Python while loop does not stop -
i writing script ask user enter date. if date format, return entry; otherwise, continue. code doesn't stop user input valid. please share insight? thanks!
def date_input(prompt): while true: date_text = raw_input(prompt) try: datetime.datetime.strptime(date_text, '%y-%m-%d') return date_text except: print('invalid input.') continue
you should never use except, check specific exception:
except valueerror: then real error should come through. suspect didn't import datetime.
Comments
Post a Comment