all Python 3calendarterm
calendar.LocaleTextCalendar
calendar classes
A text calendar that prints month and weekday names in the language of the given locale, for example locale='ru_RU.UTF-8'.
Syntax
lc = calendar.LocaleTextCalendar(firstweekday=0, locale=None)
A locale missing from the system raises locale.Error only when output is produced, not when the object is created: on a server or in a container without locale packages the code fails although it worked for the author. While formatting, the class switches the locale of the whole process, so it is not thread-safe. Russian month names may come out in the genitive case.
Examples
import calendar, locale
lc = calendar.LocaleTextCalendar(locale='ru_RU.UTF-8')
try:
print(lc.formatmonth(2024, 2).splitlines()[1]) # → ? Пн Вт Ср Чт Пт Сб Вс
except locale.Error as e:
print('нет локали:', e) # → ? нет локали: unsupported locale setting
import calendar
lc = calendar.LocaleTextCalendar() # locale=None — текущая локаль процесса
print(lc.formatweekheader(2)) # → ? зависит от локали
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy