Python calendar yeardays2calendar method explanation with example

Introduction :

In our previous post, we have seen how yeardatescalendar method works. yeardays2calendar is another method to get all days for a calendar year. It returns one list of month rows. Each row contains up to width number of months and each month contains weeks. The weekdays are a tuple of day and weekday number. If a day is not in a month, its number is 0.

Definition :

This method is defined as below :

yeardays2calendar(year, width=3)

The first parameter is the year and the second parameter is width i.e. how many months we need in each month row.

Example programs :

Let’s take a look at the below program :

import calendar

cal = calendar.Calendar()

print(cal.yeardays2calendar(2020,5))

It will print one output something like below :

[[[[(0, 0), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)], [(6, 0), (7, 1), (8, 2), (9, 3), (10, 4), (11, 5), (12, 6)], [(13, 0), (14, 1), (15, 2), (16, 3), (17, 4), (18, 5), (19, 6)], [(20, 0),......[(30, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6)]], [[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)], [(7, 0), (8, 1), (9, 2), (10, 3), (11, 4), (12, 5), (13, 6)], [(14, 0), (15, 1), (16, 2), (17, 3), (18, 4), (19, 5), (20, 6)], [(21, 0), (22, 1), (23, 2), (24, 3), (25, 4), (26, 5), (27, 6)], [(28, 0), (29, 1), (30, 2), (31, 3), (0, 4), (0, 5), (0, 6)]]]]

To learn how the data is formatted, you can try running it on your system.