Python Glossary Русский

all Python 3Exceptionsexception

locale.Error

module exceptions

An error in the locale module (e.g. an unknown locale passed to setlocale).

Syntax

raise locale.Error

The usual cause is a locale name the operating system does not know: 'ru_RU.UTF-8' works on Linux and macOS, while Windows expects something like 'Russian_Russia.1251', so a hardcoded name breaks portability. The sane reaction is to catch it and fall back to the default locale rather than crash (an empty string picks up the system setting). Keep in mind that setlocale mutates process-wide state and is not thread-safe, so calling it in the middle of a running program is asking for trouble.

Examples

import locale
try:
    raise locale.Error
except locale.Error as e:
    print(type(e).__name__)   # → Error

Open in the full glossarydocs.python.orgReport an inaccuracy