On this page
calendar.LocaleTextCalendar
Prev: calendar.LocaleHTMLCalendar | Up: calendar | Next: calendar.month
Rel: calendar.calendar, calendar.Calendar, calendar.Day, calendar.firstweekday
Ref: docs.python.org — calendar.LocaleTextCalendar
Tags: #public #python3 #stdlib #calendar
Import
import calendar
from calendar import LocaleTextCalendar
Signature & Overview
calendar.LocaleTextCalendar(firstweekday=0, locale=None)
This class can be passed a locale name in the constructor and will return month and weekday names in the specified locale.
Methods & Attributes
LocaleTextCalendar.firstweekday(...)—LocaleTextCalendar.firstweekdaymethod/property.LocaleTextCalendar.formatday(self, day, weekday, width)— Returns a formatted day.LocaleTextCalendar.formatmonth(self, theyear, themonth, w=0, l=0)— Return a month's calendar string (multi-line).LocaleTextCalendar.formatmonthname(self, theyear, themonth, width, withyear=True)—LocaleTextCalendar.formatmonthnamemethod/property.LocaleTextCalendar.formatweek(self, theweek, width)— Returns a single week in a string (no newline).LocaleTextCalendar.formatweekday(self, day, width)—LocaleTextCalendar.formatweekdaymethod/property.LocaleTextCalendar.formatweekheader(self, width)— Return a header for a week.LocaleTextCalendar.formatyear(self, theyear, w=2, l=1, c=6, m=3)— Returns a year's calendar as a multi-line string.LocaleTextCalendar.getfirstweekday(self)—LocaleTextCalendar.getfirstweekdaymethod/property.LocaleTextCalendar.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.LocaleTextCalendar.itermonthdays(self, year, month)— Like itermonthdates(), but will yield day numbers. For days outside the specified month the day number is 0.LocaleTextCalendar.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.LocaleTextCalendar.itermonthdays3(self, year, month)— Like itermonthdates(), but will yield (year, month, day) tuples. Can be used for dates outside of datetime.date range.LocaleTextCalendar.itermonthdays4(self, year, month)— Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.LocaleTextCalendar.iterweekdays(self)— Return an iterator for one week of weekday numbers starting with the configured first one.LocaleTextCalendar.monthdatescalendar(self, year, month)— Return a matrix (list of lists) representing a month's calendar.LocaleTextCalendar.monthdays2calendar(self, year, month)— Return a matrix representing a month's calendar.LocaleTextCalendar.monthdayscalendar(self, year, month)— Return a matrix representing a month's calendar.LocaleTextCalendar.prmonth(self, theyear, themonth, w=0, l=0)— Print a month's calendar.LocaleTextCalendar.prweek(self, theweek, width)— Print a single week (no newline).LocaleTextCalendar.pryear(self, theyear, w=0, l=0, c=6, m=3)— Print a year's calendar.LocaleTextCalendar.setfirstweekday(self, firstweekday)—LocaleTextCalendar.setfirstweekdaymethod/property.LocaleTextCalendar.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.LocaleTextCalendar.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 areLocaleTextCalendar.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.
Usage
import calendar
txt = calendar.LocaleTextCalendar().formatmonth(2026, 12)
assert "2026" in txt
Gotchas
- Not thread-safe: Temporarily changes the C locale while formatting month/weekday names.
REPL Inspect
from calendar import LocaleTextCalendar
help(LocaleTextCalendar)
Linked from
Related notes
- tuts/python3/stdlib_module/calendar/LocaleHTMLCalendar Linked here; links to this page; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/month Linked here; links to this page; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/calendar Linked here; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/Calendar_class Linked here; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/Day Linked here; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/firstweekday Linked here; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/calendar/HTMLCalendar shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/IllegalMonthError shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/IllegalWeekdayError shared tags: #calendar, #stdlib