Back to module index
Go to module by name
calendar
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).
Classes
Calendar
Base calendar class. This class doesn't do any formatting. It simply
provides data to subclasses.
getfirstweekday(self)
itermonthdates(self, year, month)
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(self, year, month)
Like itermonthdates(), but will yield day numbers. For days outside
the specified month the day number is 0.
itermonthdays2(self, year, month)
Like itermonthdates(), but will yield (day number, weekday number)
tuples. For days outside the specified month the day number is 0.
itermonthdays3(self, year, month)
Like itermonthdates(), but will yield (year, month, day) tuples. Can be
used for dates outside of datetime.date range.
itermonthdays4(self, year, month)
Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
Can be used for dates outside of datetime.date range.
iterweekdays(self)
Return an iterator for one week of weekday numbers starting with the
configured first one.
monthdatescalendar(self, year, month)
Return a matrix (list of lists) representing a month's calendar.
Each row represents a week; week entries are datetime.date values.
monthdays2calendar(self, year, month)
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(self, year, month)
Return a matrix representing a month's calendar.
Each row represents a week; days outside this month are zero.
setfirstweekday(self, firstweekday)
yeardatescalendar(self, year, width=3)
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.
yeardays2calendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are
(day number, weekday number) tuples. Day numbers outside this month are
zero.
yeardayscalendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are day numbers.
Day numbers outside this month are zero.
firstweekday = <property object at 0x7f92bef4bb30>
HTMLCalendar
This calendar returns complete HTML pages.
formatday(self, day, weekday)
Return a day as a table cell.
formatmonth(self, theyear, themonth, withyear=True)
Return a formatted month as a table.
formatmonthname(self, theyear, themonth, withyear=True)
Return a month name as a table row.
formatweek(self, theweek)
Return a complete week as a table row.
formatweekday(self, day)
Return a weekday name as a table header.
formatweekheader(self)
Return a header for a week as a table row.
formatyear(self, theyear, width=3)
Return a formatted year as a table of tables.
formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None)
Return a formatted year as a complete HTML page.
getfirstweekday(self)
itermonthdates(self, year, month)
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(self, year, month)
Like itermonthdates(), but will yield day numbers. For days outside
the specified month the day number is 0.
itermonthdays2(self, year, month)
Like itermonthdates(), but will yield (day number, weekday number)
tuples. For days outside the specified month the day number is 0.
itermonthdays3(self, year, month)
Like itermonthdates(), but will yield (year, month, day) tuples. Can be
used for dates outside of datetime.date range.
itermonthdays4(self, year, month)
Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
Can be used for dates outside of datetime.date range.
iterweekdays(self)
Return an iterator for one week of weekday numbers starting with the
configured first one.
monthdatescalendar(self, year, month)
Return a matrix (list of lists) representing a month's calendar.
Each row represents a week; week entries are datetime.date values.
monthdays2calendar(self, year, month)
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(self, year, month)
Return a matrix representing a month's calendar.
Each row represents a week; days outside this month are zero.
setfirstweekday(self, firstweekday)
yeardatescalendar(self, year, width=3)
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.
yeardays2calendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are
(day number, weekday number) tuples. Day numbers outside this month are
zero.
yeardayscalendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are day numbers.
Day numbers outside this month are zero.
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']
firstweekday = <property object at 0x7f92bef4bb30>
IllegalMonthError
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.
args = <attribute 'args' of 'BaseException' objects>
IllegalWeekdayError
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.
args = <attribute 'args' of 'BaseException' objects>
LocaleHTMLCalendar
This 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.
formatday(self, day, weekday)
Return a day as a table cell.
formatmonth(self, theyear, themonth, withyear=True)
Return a formatted month as a table.
formatmonthname(self, theyear, themonth, withyear=True)
formatweek(self, theweek)
Return a complete week as a table row.
formatweekday(self, day)
formatweekheader(self)
Return a header for a week as a table row.
formatyear(self, theyear, width=3)
Return a formatted year as a table of tables.
formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None)
Return a formatted year as a complete HTML page.
getfirstweekday(self)
itermonthdates(self, year, month)
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(self, year, month)
Like itermonthdates(), but will yield day numbers. For days outside
the specified month the day number is 0.
itermonthdays2(self, year, month)
Like itermonthdates(), but will yield (day number, weekday number)
tuples. For days outside the specified month the day number is 0.
itermonthdays3(self, year, month)
Like itermonthdates(), but will yield (year, month, day) tuples. Can be
used for dates outside of datetime.date range.
itermonthdays4(self, year, month)
Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
Can be used for dates outside of datetime.date range.
iterweekdays(self)
Return an iterator for one week of weekday numbers starting with the
configured first one.
monthdatescalendar(self, year, month)
Return a matrix (list of lists) representing a month's calendar.
Each row represents a week; week entries are datetime.date values.
monthdays2calendar(self, year, month)
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(self, year, month)
Return a matrix representing a month's calendar.
Each row represents a week; days outside this month are zero.
setfirstweekday(self, firstweekday)
yeardatescalendar(self, year, width=3)
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.
yeardays2calendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are
(day number, weekday number) tuples. Day numbers outside this month are
zero.
yeardayscalendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are day numbers.
Day numbers outside this month are zero.
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']
firstweekday = <property object at 0x7f92bef4bb30>
LocaleTextCalendar
This 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.
formatday(self, day, weekday, width)
Returns a formatted day.
formatmonth(self, theyear, themonth, w=0, l=0)
Return a month's calendar string (multi-line).
formatmonthname(self, theyear, themonth, width, withyear=True)
formatweek(self, theweek, width)
Returns a single week in a string (no newline).
formatweekday(self, day, width)
formatweekheader(self, width)
Return a header for a week.
formatyear(self, theyear, w=2, l=1, c=6, m=3)
Returns a year's calendar as a multi-line string.
getfirstweekday(self)
itermonthdates(self, year, month)
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(self, year, month)
Like itermonthdates(), but will yield day numbers. For days outside
the specified month the day number is 0.
itermonthdays2(self, year, month)
Like itermonthdates(), but will yield (day number, weekday number)
tuples. For days outside the specified month the day number is 0.
itermonthdays3(self, year, month)
Like itermonthdates(), but will yield (year, month, day) tuples. Can be
used for dates outside of datetime.date range.
itermonthdays4(self, year, month)
Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
Can be used for dates outside of datetime.date range.
iterweekdays(self)
Return an iterator for one week of weekday numbers starting with the
configured first one.
monthdatescalendar(self, year, month)
Return a matrix (list of lists) representing a month's calendar.
Each row represents a week; week entries are datetime.date values.
monthdays2calendar(self, year, month)
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(self, year, month)
Return a matrix representing a month's calendar.
Each row represents a week; days outside this month are zero.
prmonth(self, theyear, themonth, w=0, l=0)
Print a month's calendar.
prweek(self, theweek, width)
Print a single week (no newline).
pryear(self, theyear, w=0, l=0, c=6, m=3)
Print a year's calendar.
setfirstweekday(self, firstweekday)
yeardatescalendar(self, year, width=3)
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.
yeardays2calendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are
(day number, weekday number) tuples. Day numbers outside this month are
zero.
yeardayscalendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are day numbers.
Day numbers outside this month are zero.
firstweekday = <property object at 0x7f92bef4bb30>
TextCalendar
Subclass of Calendar that outputs a calendar as a simple plain text
similar to the UNIX program cal.
formatday(self, day, weekday, width)
Returns a formatted day.
formatmonth(self, theyear, themonth, w=0, l=0)
Return a month's calendar string (multi-line).
formatmonthname(self, theyear, themonth, width, withyear=True)
Return a formatted month name.
formatweek(self, theweek, width)
Returns a single week in a string (no newline).
formatweekday(self, day, width)
Returns a formatted week day name.
formatweekheader(self, width)
Return a header for a week.
formatyear(self, theyear, w=2, l=1, c=6, m=3)
Returns a year's calendar as a multi-line string.
getfirstweekday(self)
itermonthdates(self, year, month)
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(self, year, month)
Like itermonthdates(), but will yield day numbers. For days outside
the specified month the day number is 0.
itermonthdays2(self, year, month)
Like itermonthdates(), but will yield (day number, weekday number)
tuples. For days outside the specified month the day number is 0.
itermonthdays3(self, year, month)
Like itermonthdates(), but will yield (year, month, day) tuples. Can be
used for dates outside of datetime.date range.
itermonthdays4(self, year, month)
Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
Can be used for dates outside of datetime.date range.
iterweekdays(self)
Return an iterator for one week of weekday numbers starting with the
configured first one.
monthdatescalendar(self, year, month)
Return a matrix (list of lists) representing a month's calendar.
Each row represents a week; week entries are datetime.date values.
monthdays2calendar(self, year, month)
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(self, year, month)
Return a matrix representing a month's calendar.
Each row represents a week; days outside this month are zero.
prmonth(self, theyear, themonth, w=0, l=0)
Print a month's calendar.
prweek(self, theweek, width)
Print a single week (no newline).
pryear(self, theyear, w=0, l=0, c=6, m=3)
Print a year's calendar.
setfirstweekday(self, firstweekday)
yeardatescalendar(self, year, width=3)
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.
yeardays2calendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are
(day number, weekday number) tuples. Day numbers outside this month are
zero.
yeardayscalendar(self, year, width=3)
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are day numbers.
Day numbers outside this month are zero.
firstweekday = <property object at 0x7f92bef4bb30>
different_locale
ValueError
Inappropriate argument value (of correct type).
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.
args = <attribute 'args' of 'BaseException' objects>
repeat
repeat(object [,times]) -> create an iterator which returns the object
for the specified number of times. If not specified, returns the object
endlessly.
Functions
calendar
formatyear(theyear, w=2, l=1, c=6, m=3)
Returns a year's calendar as a multi-line string.
firstweekday
getfirstweekday()
format
format(cols, colwidth=20, spacing=6)
Prints multi-column formatting for year calendars
formatstring
formatstring(cols, colwidth=20, spacing=6)
Returns a string formatted from n strings, centered within n columns.
isleap
isleap(year)
Return True for leap years, False for non-leap years.
leapdays
leapdays(y1, y2)
Return number of leap years in range [y1, y2).
Assume y1 <= y2.
main
main(args)
month
formatmonth(theyear, themonth, w=0, l=0)
Return a month's calendar string (multi-line).
monthcalendar
monthdayscalendar(year, month)
Return a matrix representing a month's calendar.
Each row represents a week; days outside this month are zero.
monthrange
monthrange(year, month)
Return weekday (0-6 ~ Mon-Sun) and number of days (28-31) for
year, month.
prcal
pryear(theyear, w=0, l=0, c=6, m=3)
Print a year's calendar.
prmonth
prmonth(theyear, themonth, w=0, l=0)
Print a month's calendar.
prweek
prweek(theweek, width)
Print a single week (no newline).
setfirstweekday
setfirstweekday(firstweekday)
timegm
timegm(tuple)
Unrelated but handy function to calculate Unix timestamp from GMT.
week
formatweek(theweek, width)
Returns a single week in a string (no newline).
weekday
weekday(year, month, day)
Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31).
weekheader
formatweekheader(width)
Return a header for a week.
Other members
EPOCH = 1970
FRIDAY = 4
February = 2
January = 1
MONDAY = 0
SATURDAY = 5
SUNDAY = 6
THURSDAY = 3
TUESDAY = 1
WEDNESDAY = 2
c = <calendar.TextCalendar object at 0x7f92befb3c70>
day_abbr = <calendar._localized_day object at 0x7f92befb3460>
day_name = <calendar._localized_day object at 0x7f92bef9a460>
mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
month_abbr = <calendar._localized_month object at 0x7f92befb3c40>
month_name = <calendar._localized_month object at 0x7f92befb3490>
Modules
datetime
sys