Calendar module allows to output calendars like program, and provides additional useful functions related to the calendar. Functions and classes defined in Calendar module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions.
class calendar.HTMLCalendar(firstweekday=0) can be used to generate generate HTML calendars. formatyearpage() method is one of the methods of HTMLCalendar instance.
formatyearpage() method in Python is used to get year’s calendar as a complete HTML page.
Syntax: formatyearpage(year, width=3, css='calendar.css', encoding=None)
Parameter:
year: year of the calendar
width:[Default value is 3] Specifies the width date column
css: [Optional] Name for the CSS to be used.
encoding: [Optional] Specifies the encoding to be used for output
Returns: Return an HTML page for an entire year.
Depends on the first weekday as specified in the constructor or set by the
setfirstweekday() method.
Code #1:
Output:
Note that the earliest year for which a calendar can be generated is platform-dependent.
Code #2: width is given 5
Output:
HTMLCalendar has few attributes you can override to customize the CSS classes used by the calendar. One of the attribute is cssclasses.
cssclasses is the list of CSS classes used for each weekday. Default list is cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]. Style can be modified for each day, for ex - ["mon text-bold", "tue", "wed", "thu", "fri", "sat", "sun red"]