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

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -