figuring week of the day....
tekion
tekion at gmail.com
Sat Jan 17 12:20:34 EST 2009
On Jan 9, 6:05 am, Tim Chase <python.l... at tim.thechases.com> wrote:
> Tim Chase wrote:
> > tekion wrote:
> >> Is there a module where you could figure week of the day, like where
> >> it starts and end. I need to do this for a whole year. Thanks.
>
> > the monthcalendar() call returns the whole month's calendar which
> > may be more what you want for the big-picture.
>
> And if you want a whole year's worth, you can get pretty close with:
>
> import itertools as i
> import calendar as c
> for month in range(1,13):
> for week in c.monthcalendar(2009, month):
> print repr(w)
>
> You don't detail how you want the month-boundaries to behave, so
> this gives "calendar"'s default behavior of filling in zeros on
> month-boundaries, so November through the 1st week in Dec 2009
> comes back as
>
> ...
> [0, 0, 0, 0, 0, 0, 1],
> [2, 3, 4, 5, 6, 7, 8],
> [9, 10, 11, 12, 13, 14, 15],
> [16, 17, 18, 19, 20, 21, 22],
> [23, 24, 25, 26, 27, 28, 29],
> [30, 0, 0, 0, 0, 0, 0],
> [0, 1, 2, 3, 4, 5, 6],
> ...
>
> rather than
>
> ...
> [26, 27, 28, 29, 30, 31, 1],
> [2, 3, 4, 5, 6, 7, 8],
> [9, 10, 11, 12, 13, 14, 15],
> [16, 17, 18, 19, 20, 21, 22],
> [23, 24, 25, 26, 27, 28, 29],
> [30, 1, 2, 3, 4, 5, 6],
> ...
>
> -tkc
Thanks, this is exactly what I am looking for. I will give it a try.
Do you what argument or documentation I should read up on how to get
the month's boundary rather than the default. I would assume it's
just an argument I give when creating the month object.
More information about the Python-list
mailing list