Date validation

Fredrik Lundh fredrik at pythonware.com
Fri Apr 25 12:24:51 EDT 2003


Andrew Bennetts wrote:

> > > I mean I *could* write this myself, but I had to ask the computer how
> > > many days in April - someone with a better grasp of the date must have
> > > written this stuff before :)
> >
> > don't you have any knuckles on your left hand?
>
> And which knuckles do you use to remember which years are leap years?  ;)

in what part of the world does the number of days in April
vary depending on the year?

> > if you want your program to check how many days there are in
> > a given month, use the calendar module:
>
> He does.  In his words: "how can I check whether or not such strings
> represent a valid date?"
>
> His problem is verifying that the entire date is correct.  By the time you
> factor in the varying days of the months and leap years, I can understand
> wanting to use a prewritten and tested module rather than an ad-hoc solution
> for a problem that many people must have encountered before.

"calendar" is a prewritten and tested module, and has been part
of Python's standard library since around 1066 AD.

by using calender, he can add 3-4 lines of obviously correct code
to his program, and move on to the next problem...

in contrast, you're suggesting that he

1) update to a newer Python version, and end up with a program
that may or may not work if run on an older version, or

2) backport changes to a newer Python version to his own Python
install, and end up with a nonstandard Python environment and a
program that may or may not work if run on an older version, or

3) add 550 lines of recently written, rather complex, and yet to be
widely used code to his application, and end up with a program that
may or may not work...

but I can of course not stop him from doing things in the hardest
possible way; I'm just pointing out that there's another way to solve
his problem using tools that's already installed on his machine... if
you have a problem with that, that's your problem.

(it could be worse, of course: I'm still waiting for the let's-use-a-
metaclass crowd to discover this thread...)

</F>








More information about the Python-list mailing list