script for seconds in given month?

pythoncurious at gmail.com pythoncurious at gmail.com
Tue Apr 17 09:47:11 CEST 2007


On Apr 17, 6:41 am, a... at mac.com (Alex Martelli) wrote:
> edfialk <edfi... at gmail.com> wrote:
> > Hi, does anyone happen to know of ascriptthat would return the
> > number ofsecondsin amonthif I give it amonthand a year?
>
> > My python is a little weak, but if anyone could offer some suggestions
> > I think I could handle it myself, or if anyone happens to know of a
> >scriptalready written that performs this I would be extremely
> > grateful.
>
> import calendar
>
> def seconds_in_month(month, year):
>     nomatter, daysinmonth = calendar.monthrange(year,month)
>     return daysinmonth * 24 * 60 * 60
>
> Alex

That works if you define the number of seconds in a month a the number
of days * 24 * 60 * 60.
If you have DST then that's not always the truth. The difference in
seconds (clock time) is according to your example, but the number of
seconds that passed during the month differs.
Not sure which one was requested in the original post though.






More information about the Python-list mailing list