Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!news2.arglkargh.de!easy.in-chemnitz.de!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'except:': 0.07; 'exception.': 0.07; 'raises': 0.07; 'skip:% 20': 0.07; 'try:': 0.07; 'subject:skip:a 10': 0.09; 'to:addr:comp.lang.python': 0.09; 'valueerror': 0.09; 'cc:addr :python-list': 0.10; 'properly': 0.15; "'%d": 0.16; 'doesnt': 0.16; 'supress': 0.16; 'cc:2**0': 0.23; 'task': 0.23; 'cc:no real name:2**0': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'workaround': 0.29; 'handle': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'thank': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'you.': 0.61; 'price': 0.66; 'received:209.85.220.184': 0.91 X-Received: by 10.49.63.164 with SMTP id h4mr66343qes.39.1361533543456; Fri, 22 Feb 2013 03:45:43 -0800 (PST) Newsgroups: comp.lang.python Date: Fri, 22 Feb 2013 03:45:43 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=94.68.75.81; posting-account=DYJQ-woAAACEPH85Au2BhUVfFTfSfVa4 References: <92536c34-cf00-4497-b646-ab79fa4ee062@googlegroups.com> <5bac38bb-df2e-47b8-96dd-2b1c090959e4@googlegroups.com> <49de0696-b6f6-42ce-9272-79dac37c9605@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 94.68.75.81 MIME-Version: 1.0 Subject: Re: Checking for valid date input and convert appropriately From: Ferrous Cranus To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 10 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361534127 news.xs4all.nl 6855 [2001:888:2000:d::a6]:36362 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39553 > 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.