calendar module#
Calendar printing functions
Note when comparing these calendars to the ones printed by cal(1): By default, these calendars have Monday as the first day of the week, and Sunday as the last (the European convention). Use setfirstweekday() to set the first day of the week (0=Monday, 6=Sunday).
- class calendar.Calendar(firstweekday=0)[source]#
Bases:
objectBase calendar class. This class doesn’t do any formatting. It simply provides data to subclasses.
- property firstweekday#
- itermonthdates(year, month)[source]#
Return an iterator for one month. The iterator will yield datetime.date values and will always iterate through complete weeks, so it will yield dates outside the specified month.
- itermonthdays(year, month)[source]#
Like itermonthdates(), but will yield day numbers. For days outside the specified month the day number is 0.
- itermonthdays2(year, month)[source]#
Like itermonthdates(), but will yield (day number, weekday number) tuples. For days outside the specified month the day number is 0.
- itermonthdays3(year, month)[source]#
Like itermonthdates(), but will yield (year, month, day) tuples. Can be used for dates outside of datetime.date range.
- itermonthdays4(year, month)[source]#
Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples. Can be used for dates outside of datetime.date range.
- iterweekdays()[source]#
Return an iterator for one week of weekday numbers starting with the configured first one.
- monthdatescalendar(year, month)[source]#
Return a matrix (list of lists) representing a month’s calendar. Each row represents a week; week entries are datetime.date values.
- monthdays2calendar(year, month)[source]#
Return a matrix representing a month’s calendar. Each row represents a week; week entries are (day number, weekday number) tuples. Day numbers outside this month are zero.
- monthdayscalendar(year, month)[source]#
Return a matrix representing a month’s calendar. Each row represents a week; days outside this month are zero.
- yeardatescalendar(year, width=3)[source]#
Return the data for the specified year ready for formatting. The return value is a list of month rows. Each month row contains up to width months. Each month contains between 4 and 6 weeks and each week contains 1-7 days. Days are datetime.date objects.
- class calendar.HTMLCalendar(firstweekday=0)[source]#
Bases:
calendar.CalendarThis calendar returns complete HTML pages.
- cssclass_month = 'month'#
- cssclass_month_head = 'month'#
- cssclass_noday = 'noday'#
- cssclass_year = 'year'#
- cssclass_year_head = 'year'#
- cssclasses = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']#
- cssclasses_weekday_head = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']#
- exception calendar.IllegalMonthError(month)[source]#
Bases:
ValueError
- exception calendar.IllegalWeekdayError(weekday)[source]#
Bases:
ValueError
- class calendar.LocaleHTMLCalendar(firstweekday=0, locale=None)[source]#
Bases:
calendar.HTMLCalendarThis class can be passed a locale name in the constructor and will return month and weekday names in the specified locale. If this locale includes an encoding all strings containing month and weekday names will be returned as unicode.
- class calendar.LocaleTextCalendar(firstweekday=0, locale=None)[source]#
Bases:
calendar.TextCalendarThis class can be passed a locale name in the constructor and will return month and weekday names in the specified locale. If this locale includes an encoding all strings containing month and weekday names will be returned as unicode.
- class calendar.TextCalendar(firstweekday=0)[source]#
Bases:
calendar.CalendarSubclass of Calendar that outputs a calendar as a simple plain text similar to the UNIX program cal.
- calendar.calendar(theyear, w=2, l=1, c=6, m=3)#
Returns a year’s calendar as a multi-line string.
- calendar.firstweekday()#
- calendar.month(theyear, themonth, w=0, l=0)#
Return a month’s calendar string (multi-line).
- calendar.monthcalendar(year, month)#
Return a matrix representing a month’s calendar. Each row represents a week; days outside this month are zero.
- calendar.monthrange(year, month)[source]#
Return weekday (0-6 ~ Mon-Sun) and number of days (28-31) for year, month.
- calendar.prcal(theyear, w=0, l=0, c=6, m=3)#
Print a year’s calendar.
- calendar.prmonth(theyear, themonth, w=0, l=0)#
Print a month’s calendar.
- calendar.weekday(year, month, day)[source]#
Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31).
- calendar.weekheader(width)#
Return a header for a week.