On this page
locale.setlocale
Prev: locale.normalize | Up: locale | Next: locale.str
Rel: locale.atof, locale.atoi, locale.currency, locale.Error
Ref: docs.python.org — locale.setlocale
Tags: #public #python3 #stdlib #locale
Import
import locale
from locale import setlocale
Signature & Overview
locale.setlocale(category, locale=None)
Set the locale for the given category. The locale can be a string, an iterable of two strings (language code and encoding), or None.
Usage
import locale
# Querying (passing None) is safe; mutating is process-global and NOT thread-safe
cur = locale.setlocale(locale.LC_CTYPE)
assert isinstance(cur, str)
Gotchas
- Process-global and NOT thread-safe: Only call
setlocale(LC_ALL, "")once at CLI startup, never inside libraries or web handlers.
REPL Inspect
from locale import setlocale
help(setlocale)
Linked from
Related notes
- tuts/python3/stdlib_module/locale/normalize Linked here; links to this page; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/str Linked here; links to this page; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/locale/atof Linked here; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/atoi Linked here; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/currency Linked here; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/Error Linked here; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/format_string shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/getdefaultlocale shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/getencoding shared tags: #locale, #stdlib