Python Glossary Русский

all Python 3calendarterm

calendar.LocaleHTMLCalendar

calendar classes

An HTML calendar that renders month and weekday names in the language of the given locale, for example locale='ru_RU.UTF-8'.

Syntax

lh = calendar.LocaleHTMLCalendar(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
lh = calendar.LocaleHTMLCalendar(locale='ru_RU.UTF-8')
try:
    print(lh.formatmonthname(2024, 2))  # → ? строка таблицы с «Февраль 2024»
except locale.Error as e:
    print('нет локали:', e)  # → ? нет локали: unsupported locale setting
import calendar
lh = calendar.LocaleHTMLCalendar(locale='C')
print(lh.formatmonthname(2024, 2))  # → ? в локали C — February 2024

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy