Checking for valid date input and convert appropriately

Ferrous Cranus nikos.gr33k at gmail.com
Fri Feb 22 06:45:43 EST 2013


> I'am thinking if somehting like the follwoing work:
> 
> if( task and ( price and price.isdigit() and price.__len__() <= 3 ) and ( date and eval( datetime.strptime(date, '%d %m %Y').strftime('%Y-%m-%d') ) ) ):

I just tried it out this workaround so to avoid having an extra try: except: but if the user doesnt enter the date properly it still raises a ValueError exception.

Is there a way to still use the if statemnt and somehow supress the message nd let else: handle it somehow?

thank you.



More information about the Python-list mailing list