Python Glossary Русский

all Python 3until 3.13Removed from the standard libraryfunction

locale.resetlocale()

removed

Reset the locale to the environment settings. Removed in Python 3.13 — use locale.setlocale(locale.LC_ALL, '') instead.

Syntax

locale.resetlocale()  # до 3.13

The function restored the locale from the environment (LANG, LC_ALL) after a program had changed it with setlocale. It was removed because it built the locale name through getdefaultlocale and on some systems picked the wrong locale or failed with locale.Error. The fix is one line: replace locale.resetlocale() with locale.setlocale(locale.LC_ALL, '') — the empty string means "take it from the environment"; for a single category pass it instead of LC_ALL, e.g. locale.setlocale(locale.LC_TIME, '').

Examples

# Python 3.13+
import locale
try:
    locale.resetlocale
except AttributeError as e:
    print(type(e).__name__)  # → AttributeError
# Python 3.13+
import locale
current = locale.setlocale(locale.LC_ALL, '')  # локаль окружения
print(current == locale.setlocale(locale.LC_ALL))  # → True
import locale
locale.resetlocale()  # → ? locale.Error, если локали из окружения нет в системе
print(type(locale.setlocale(locale.LC_ALL)).__name__)  # → str

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy