figuring week of the day....

Tim Chase tim at
Thu Jan 8 20:52:38 CET 2009

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.

sounds like you want the standard library's "calendar" module, 
particularly the monthcalendar() which gets you pretty close.

For a lazy version just using the stdlib with minimal fuss:

   >>> 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)
   [5, 6, 7, 8, 9, 10, 11]

the monthcalendar() call returns the whole month's calendar which 
may be more what you want for the big-picture.


More information about the Python-list mailing list