[Tutor] Exception Handling
Kent Johnson
kent37 at tds.net
Tue Dec 30 23:29:22 CET 2008
On Tue, Dec 30, 2008 at 4:33 PM, David <david at abbottdavid.com> wrote:
> Thank you all for the tips. Next to do is to get the dates in one raw_input
> with the correct format and to check for a valid year, month, and day. Here
> is what I have now;
> ynum = int(time.strftime("%Y", time.gmtime())) - int(yr)
> mnum = int(time.strftime("%m", time.gmtime()))
> dnum = int(time.strftime("%d", time.gmtime()))
Yikes! How about time.gmtime().tm_year, etc, instead of all the calls
to strftime() and int()? And you might want to put the value of
time.gmtime() in a variable so you always use the same value, just in
case someone runs your program on New Year's Eve at midnight.
You might also want to look at the datetime module, in particular
datetime.timedelta.
Kent
More information about the Tutor
mailing list