Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'except:': 0.07; 'try:': 0.07; 'function:': 0.09; 'subject:skip:a 10': 0.09; 'to:addr:comp.lang.python': 0.09; 'way:': 0.09; 'cc:addr:python- list': 0.10; 'def': 0.10; '1900': 0.16; 'dislike': 0.16; 'emanuele': 0.16; 'len(parts)': 0.16; 'helper': 0.17; 'putting': 0.20; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'wrote': 0.26; 'done.': 0.27; 'writes:': 0.29; 'message.': 0.33; 'received:google.com': 0.34; 'false': 0.35; 'but': 0.36; "i'll": 0.36; 'ok,': 0.37; 'why': 0.37; 'previous': 0.37; 'subject:: ': 0.38; 'instead': 0.39; '8bit%:95': 0.61; 'more': 0.63; '8bit%:100': 0.70; '8bit%:92': 0.70; '2013': 0.84; 'hassle.': 0.84; 'quando': 0.84 X-Received: by 10.50.5.244 with SMTP id v20mr162945igv.13.1361545633608; Fri, 22 Feb 2013 07:07:13 -0800 (PST) Newsgroups: comp.lang.python Date: Fri, 22 Feb 2013 07:07:13 -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> <0065de90-75e4-4a50-b084-be6c8c7e5f23@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=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361548007 news.xs4all.nl 6858 [2001:888:2000:d::a6]:57522 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39584 =CE=A4=CE=B7 =CE=A0=CE=B1=CF=81=CE=B1=CF=83=CE=BA=CE=B5=CF=85=CE=AE, 22 =CE= =A6=CE=B5=CE=B2=CF=81=CE=BF=CF=85=CE=B1=CF=81=CE=AF=CE=BF=CF=85 2013 3:35:3= 1 =CE=BC.=CE=BC. UTC+2, =CE=BF =CF=87=CF=81=CE=AE=CF=83=CF=84=CE=B7=CF=82 L= ele Gaifax =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: > Ferrous Cranus writes: >=20 >=20 >=20 > > Let me ask it like this: >=20 > > How can i avoid using try: except: for checkign the date but instead ch= eck it with an if statement: >=20 >=20 >=20 > Let me answer this way: you can't, without resorting to the simple >=20 > helper functions I wrote in my previous message.=20 >=20 >=20 >=20 > Why do you dislike that solution? >=20 >=20 >=20 > ciao, lele. >=20 > --=20 >=20 > nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri >=20 > real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. >=20 > lele@metapensiero.it | -- Fortunato Depero, 1929. ok, i'll just use the try: except: i was just thinking putting them all in = the same if() statemt but apparently it cant be done. Actually it can, but instead of try: i have to create a function: def is_sane_date(date): parts =3D [int(part) for part in date.split() if part.isdigit()] if len(parts) =3D=3D 3 and \ 1 <=3D parts[0] <=3D 31 and \ 1 <=3D parts[1] <=3D 12 and \ 1900 <=3D parts[2] <=3D 2100: return True return False if is_sane_date(date): # ... but the try: solution is much more less hassle.