theyear | Year number for which calendar of the month is returned |
themonth | Month number for which calendar of the month is returned |
w | Optional , default =0 , width of date column |
l | Optional , default =0 , number of line each week will use |
import calendar
x=calendar.TextCalendar() #
x.prmonth(2020,7,w=5,l=1)
Output
July 2020
Mon Tue Wed Thu Fri Sat Sun
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
Based on the setting of first day of the week, the calendar first weekday can be set. Week day number starts from 0 as Monday , 1 as Tuesday and ends at 6 as Sunday.
import calendar
x=calendar.TextCalendar()
x.setfirstweekday(4) # first week day is Friday
x.prmonth(theyear=2020,themonth=7,w=3,l=0)
Output
July 2020
Fri Sat Sun Mon Tue Wed Thu
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
Calendar Module in Python itermonthdays()
itermonthdays2()
itermonthdays3()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.