Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Checking for valid date input and convert appropriately

Reply
Thread Tools

Checking for valid date input and convert appropriately

 
 
Lele Gaifax
Guest
Posts: n/a
 
      02-22-2013
Ferrous Cranus <(E-Mail Removed)> writes:

> Let me ask it like this:
> How can i avoid using try: except: for checkign the date but instead check it with an if statement:


Let me answer this way: you can't, without resorting to the simple
helper functions I wrote in my previous message.

Why do you dislike that solution?

ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
http://www.velocityreviews.com/forums/(E-Mail Removed) | -- Fortunato Depero, 1929.

 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      02-22-2013
On Sat, Feb 23, 2013 at 12:35 AM, Lele Gaifax <(E-Mail Removed)> wrote:
> Ferrous Cranus <(E-Mail Removed)> writes:
>
>> Let me ask it like this:
>> How can i avoid using try: except: for checkign the date but instead check it with an if statement:

>
> Let me answer this way: you can't, without resorting to the simple
> helper functions I wrote in my previous message.
>
> Why do you dislike that solution?


This is very similar to the previous threads that the OP has engaged
in recently. He asks a question of the form "How can I do X, without
using facility Y" where Y is the obvious way to do X.

http://redwing.hutman.net/~mreed/war...rouscranus.htm

My days of not taking him seriously are certainly coming to a middle.

ChrisA
 
Reply With Quote
 
 
 
 
Andreas Perstinger
Guest
Posts: n/a
 
      02-22-2013
Lele Gaifax <(E-Mail Removed)> wrote:
>Ferrous Cranus <(E-Mail Removed)> writes:
>
>> Let me ask it like this:
>> How can i avoid using try: except: for checkign the date but instead
>> check it with an if statement:

>
>Let me answer this way: you can't, without resorting to the simple
>helper functions I wrote in my previous message.
>
>Why do you dislike that solution?


Ferrous Cranus has proven in previous discussions (search the archives)
that he doesn't like common-sense solutions and insists on doing it his
own way (although his methods are either wrong or impossible).

Don't waste your time.

Bye, Andreas
 
Reply With Quote
 
Ferrous Cranus
Guest
Posts: n/a
 
      02-22-2013
Τη *αρασκευή, 22 Φεβρουαρίου 2013 3:35:31 μ.μ. UTC+2, ο χρήστης Lele Gaifax *γραψε:
> Ferrous Cranus <(E-Mail Removed)> writes:
>
>
>
> > Let me ask it like this:

>
> > How can i avoid using try: except: for checkign the date but instead check it with an if statement:

>
>
>
> Let me answer this way: you can't, without resorting to the simple
>
> helper functions I wrote in my previous message.
>
>
>
> Why do you dislike that solution?
>
>
>
> ciao, lele.
>
> --
>
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
>
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
>
> (E-Mail Removed) | -- 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 = [int(part) for part in date.split() if part.isdigit()]
if len(parts) == 3 and \
1 <= parts[0] <= 31 and \
1 <= parts[1] <= 12 and \
1900 <= parts[2] <= 2100:
return True
return False

if is_sane_date(date):
# ...

but the try: solution is much more less hassle.
 
Reply With Quote
 
Ferrous Cranus
Guest
Posts: n/a
 
      02-22-2013
Τη *αρασκευή, 22 Φεβρουαρίου 2013 3:35:31 μ.μ. UTC+2, ο χρήστης Lele Gaifax *γραψε:
> Ferrous Cranus <(E-Mail Removed)> writes:
>
>
>
> > Let me ask it like this:

>
> > How can i avoid using try: except: for checkign the date but instead check it with an if statement:

>
>
>
> Let me answer this way: you can't, without resorting to the simple
>
> helper functions I wrote in my previous message.
>
>
>
> Why do you dislike that solution?
>
>
>
> ciao, lele.
>
> --
>
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
>
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
>
> (E-Mail Removed) | -- 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 = [int(part) for part in date.split() if part.isdigit()]
if len(parts) == 3 and \
1 <= parts[0] <= 31 and \
1 <= parts[1] <= 12 and \
1900 <= parts[2] <= 2100:
return True
return False

if is_sane_date(date):
# ...

but the try: solution is much more less hassle.
 
Reply With Quote
 
Lele Gaifax
Guest
Posts: n/a
 
      02-22-2013
Ferrous Cranus <(E-Mail Removed)> writes:

> but the try: solution is much more less hassle.


.... not to mention it is more effective than your simplicistic check

ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
(E-Mail Removed) | -- Fortunato Depero, 1929.

 
Reply With Quote
 
Tim Chase
Guest
Posts: n/a
 
      02-22-2013
On 2013-02-22 07:07, Ferrous Cranus wrote:
> Actually it can, but instead of try: i have to create a function:
>
> def is_sane_date(date):
> parts = [int(part) for part in date.split() if part.isdigit()]
> if len(parts) == 3 and \
> 1 <= parts[0] <= 31 and \
> 1 <= parts[1] <= 12 and \
> 1900 <= parts[2] <= 2100:
> return True
> return False


Then you have things like "31 2 2013" being a valid date. Also, the
hard caps at 1900 and 2100 are both pretty short-sighted. To the
best of my knowledge, there are valid dates outside that date
range

-tkc


 
Reply With Quote
 
Ferrous Cranus
Guest
Posts: n/a
 
      02-22-2013
Τη *αρασκευή, 22 Φεβρουαρίου 2013 5:25:41 μ.μ. UTC+2, ο χρήστης Lele Gaifax *γραψε:
> Ferrous Cranus <(E-Mail Removed)> writes:
>
>
>
> > but the try: solution is much more less hassle.

>
>
>
> ... not to mention it is more effective than your simplicistic check
>
>
>
> ciao, lele.
>
> --
>
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
>
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
>
> (E-Mail Removed) | -- Fortunato Depero, 1929.



 
Reply With Quote
 
Ferrous Cranus
Guest
Posts: n/a
 
      02-22-2013
Τη *αρασκευή, 22 Φεβρουαρίου 2013 5:25:41 μ.μ. UTC+2, ο χρήστης Lele Gaifax *γραψε:
> Ferrous Cranus <(E-Mail Removed)> writes:
>
>
>
> > but the try: solution is much more less hassle.

>
>
>
> ... not to mention it is more effective than your simplicistic check
>
>
>
> ciao, lele.
>
> --
>
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
>
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
>
> (E-Mail Removed) | -- Fortunato Depero, 1929.



 
Reply With Quote
 
Ferrous Cranus
Guest
Posts: n/a
 
      02-22-2013
Τη *αρασκευή, 22 Φεβρουαρίου 2013 7:38:47 μ.μ. UTC+2, ο χρήστης Ferrous Cranus *γραψε:
> Τη *αρασκευή, 22 Φεβρουαρίου 2013 5:25:41 μ.μ. UTC+2, ο χρήστης Lele Gaifax *γραψε:
>
> > Ferrous Cranus <(E-Mail Removed)> writes:

>
> >

>
> >

>
> >

>
> > > but the try: solution is much more less hassle.

>
> >

>
> >

>
> >

>
> > ... not to mention it is more effective than your simplicistic check

>
> >

>
> >

>
> >

>
> > ciao, lele.

>
> >

>
> > --

>
> >

>
> > nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri

>
> >

>
> > real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.

>
> >

>
> > (E-Mail Removed) | -- Fortunato Depero, 1929.

>
>
>
>


True
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get DIV height in IE6 to set appropriately (IE7 works fine) Richard.Gohs@pa-tech.com HTML 1 09-24-2008 08:14 AM
How do I tell "imconplete input" from "valid input"? $B$?$+(B Python 2 05-29-2008 10:32 AM
Using size_t clearly (appropriately?) Mark Odell C Programming 40 07-13-2006 06:19 AM
Return appropriately by value, (smart) pointer, or reference Neal Coombes C++ 5 09-22-2005 10:22 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments