El módulo de calendario permite generar calendarios como un programa y proporciona funciones útiles adicionales relacionadas con el calendario. Las funciones y clases definidas en el módulo Calendario utilizan un calendario idealizado, el actual calendario gregoriano extendido indefinidamente en ambas direcciones.
El método yeardayscalendar() en Python se usa para obtener los datos del año especificado. Las entradas en las listas de semana son números de día. Los números de días fuera de este mes son cero.
Syntax: yeardayscalendar(year, width) Parameter: year: year of the calendar width: [Default: 3] number of months in each row. Returns: list of day numbers.
Código #1:
Python3
# Python program to demonstrate working # of yeardayscalendar() method # importing calendar module import calendar obj = calendar.Calendar() year = 2016 # default value of width is 3 # printing with yeardayscalendar print(obj.yeardayscalendar(year))
Producción:
[[[[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, 31]], [[1, 2, 3, 4, 5, 6, 7] …
…
[[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, 31, 0]]]]
Código #2: iterando la lista de semanas
Python3
# Python program to demonstrate working # of yeardayscalendar() method # importing calendar module import calendar obj = calendar.Calendar() # iterating with yeardayscalendar for day in obj.yeardayscalendar(2018, 1): print(day)
Producción:
[[[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, 31, 0, 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, 0, 0, 0, 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], [ 31, 0, 0, 0, 0, 0, 0]]]