T
tekion
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.
it starts and end. I need to do this for a whole year. Thanks.
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.
tekion said: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.
[5, 6, 7, 8, 9, 10, 11]>>> import calendar as c
>>> week = lambda y,m,d: [w for w in c.monthcalendar(y, m) if d in w][0]
>>> week(2009, 1, 8)
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.
Tim said:the monthcalendar() call returns the whole month's calendar which
may be more what you want for the big-picture.
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
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.