Thursday, 14 July 2016

Python: Calendar: Get month calendar

'calendar.monthcalendar(year, month)' is used to get month calendar. Days outside of month are represented as zeros.

>>> import calendar
>>> calendar.monthcalendar(2015,11)
[[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]]
>>> 
>>> for week in calendar.monthcalendar(2015,11):
...     print(week)
... 
[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]


Previous                                                 Next                                                 Home

No comments:

Post a Comment