Custom Search

Saturday, March 27, 2010

how get all days in a month in matrix form python

how get all days in a month in matrix form python

----------------------

import calendar
calendar.setfirstweekday(calendar.SUNDAY) # to set week beginning to Sunday, by default it is Monday
days = calendar.monthcalendar(2010, 2)
print days

---------------------

calendar.monthcalendar(year, month)

Returns a matrix representing a month’s calendar.
Each row represents a week; days outside of the month a represented by zeros.
Each week begins with Monday unless set by setfirstweekday().

---------------------
calendar.setfirstweekday(weekday)

Sets the weekday (0 is Monday, 6 is Sunday) to start each week.
The values MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, and SUNDAY are provided for convenience.
For example, to set the first weekday to Sunday:

import calendar
calendar.setfirstweekday(calendar.SUNDAY)

---------------------
For more details
http://docs.python.org/library/calendar.html

---------------------

No comments:

Post a Comment