Python Calendar Module | HTMLCalendar formatyearpage () method

Python Methods and Functions

Class calendar.HTMLCalendar(firstweekday=0) can be used to generate generated HTML calendars. The formatyearpage () method is one of the HTMLCalendar instance methods.

formatyearpage() in Python is used to get the calendar of the year as a full 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 day of the week as specified in the constructor or set by the setfirstweekday () method .

Code # 1:

# Python program to demonstrate the formatyearpage () method

  
# import calendar module

import calendar

 

text_cal = calendar.HTMLCalendar (firstweekday = 0 )

 

year = 2018

# The default width is 3

 
# print format page

print (text_cal.formatyearpage (year))

Exit:

b'

& lt ;? xml version = "1.0" encoding = "utf-8" ? & gt;

& lt;! DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.0 Strict // EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict. dtd "& gt;

& lt; html & gt;

& lt; head & gt;

& lt; meta http-equiv = "Content-Type" content = "text / html; charset = utf-8" / & gt;

 

& lt; link rel = "stylesheet" type = "text / css " href = " calendar.css " / & gt;

& lt; title & gt; Calendar for 2018 & lt; / title & gt;

& lt; / head & gt;

 

& lt; body & gt;

& lt; table border = "0" cellpadding = "0" cellspacing = "0" class = "year" & gt;

& lt; tr & gt;

& lt; th colspan = "3" class = "year" & gt; 2018 & lt; / th & gt;

& lt; / tr & gt;

& lt; tr & gt;

& lt; td & gt;

& lt; table border = "0" cellpadding = "0" cellspacing = "0" class = "month" & gt;

& lt; tr & gt;

& lt; th colspan = "7" class = "month" & gt; January & lt; / th & gt;

& lt; / tr & gt;

& lt; tr & gt;

& lt; th class = "mon" & gt; Mon & lt; / th & gt;

& lt; th class = "tue" & gt; Tue & lt; / th & gt;

& lt; th class = "wed" & gt; Wed & lt; / th & gt;

& lt; th class = "thu" & gt; Thu & lt; / th & gt;

& lt; th class = "fri" & gt; Fri & lt; / th & gt;

& lt; th class = "sat" & gt; Sat & lt; / th & gt;

& lt; th class = "sun" & gt; Sun & lt; / th & gt;

& lt; / tr & gt;

 

& lt; tr & gt;

& lt; td class = "mon" & gt; 1 & lt; / td & gt;

& lt; td class = "tue" & gt; 2 & lt; / td & gt;

& lt; td class = "wed" & gt; 3 & lt; / td & gt;

& lt; td class = "thu" & gt; 4 & lt; / td & gt;

& lt; td class = "fri" & gt; 5 & lt; / td & gt;

& lt; td class = "sat" & gt; 6 & lt; / td & gt;

& lt; td class = "sun" & gt; 7 & lt; / td & gt;

& lt; / tr & gt;

& lt; tr & gt;

& lt; td class = "mon" & gt; 8 & lt; / td & gt;

& lt; td class = "tue" & gt; 9 & lt; / td & gt;

& lt; td class = "wed" & gt; 10 & lt; / td & gt;

& lt; td class = "thu" & gt; 11 & lt; / td & gt;

& lt; td class = "fri" & gt; 12 & lt; / td & gt;

& lt; td class = "sat" & gt; 13 & lt; / td & gt;

& lt; td class = "sun" & gt; 14 & lt; / td & gt;

& lt; / tr & gt;

 

& lt; tr & gt;

& lt; td class = "mon" & gt; 15 & lt; / td & gt;

& lt; td class = "tue" & gt; 16 & lt; / td & gt;

& lt; td class = "wed" & gt; 17 & lt; / td & gt;

& lt; td class = "thu" & gt; 18 & lt; / td & gt;

& lt; td class = "fri" & gt; 19 & lt; / td & gt;

& lt; td class = "sat" & gt; 20 & lt; / td & gt;

& lt; td class = "sun" & gt; 21 & lt; / td & gt;

& lt; / tr & gt;

& lt; tr & gt;

& lt; td class = "mon" & gt; 22 & lt; / td & gt;

& lt; td class = "tue" & gt; 23 & lt; / td & gt;

& lt; td class = "wed" & gt; 24 & lt; / td & gt;

& lt; td class = "thu" & gt; 25 & lt; / td & gt;

& lt; td class = "fri" & gt; 26 & lt; / td & gt;

& lt; td class = "sat" & gt; 27 & lt; / td & gt;

& lt; td class = "sun" & gt; 28 & lt; / td & gt;

& lt; / tr & gt;

& lt; tr & gt;

& lt; td class = "mon" & gt; 29 & lt; / td & gt;

& lt; td class = "tue" & gt; 30 & lt; / td & gt;

& lt; td class = "wed" & gt; 31 & lt; / td & gt;

& lt; td class = "noday" & gt; & lt; / td & gt;

& lt; td class = "noday" & gt; & lt; / td & gt;

& lt; td class = "noday" & gt; & lt; / td & gt;

& lt; td class = "noday" & gt; & lt; / td & gt;

& lt; / tr & gt;

& lt; / table & gt;

& lt; / td & gt;

& lt; td & gt;

& lt; table border = "0" cellpadding = "0" cellspacing = "0" class = "month" & gt;

& lt; tr & gt;

& lt; th colspan = "7" class = "month" & gt; February & lt; / th & gt;

& lt; / tr & gt;

& lt; tr & gt;

& lt; th class = "mon" & gt; Mon & lt; / th & gt;

& lt; th class = "tue" & gt; Tue & lt; / th & gt;

& lt; th class = "wed" & gt; Wed & lt; / th & gt;

& lt; th class = "thu" & gt; Thu & lt; / th & gt;

& lt; th class = "fri" & gt; Fri & lt; / th & gt;

& lt; th class = "sat" & gt; Sat & lt; / th & gt;

& lt; th class = "sun" & gt; Sun & lt; / th & gt;

& lt; / tr & gt;

& lt; tr & gt;

& lt; td class = "noday" & gt; & lt; / td & gt;

& lt; td class = "noday" & gt; & lt; / td & gt;

& lt; td class = "noday" & gt; & lt; / td & gt;

& lt; td class = "thu" & gt; 1 & lt; / td & gt;

& lt; td class = "fri" & gt; 2 & lt; / td & gt;

& lt; td class = "sat" & gt; 3 & lt; / td & gt;

& lt; td class = "sun" & gt; 4 & lt; / td & gt;

& lt; / tr & gt;

& lt;


Get Solution for free from DataCamp guru