all Python 3localefunction
locale.getlocale()
locale setup
Returns the current locale of a category as a (language code, encoding) tuple; the default category is LC_CTYPE.
Syntax
locale.getlocale(category=LC_CTYPE)
The 'C' locale is reported as (None, None), not as the string 'C', so lang.startswith(...) blows up on None. Python sets LC_CTYPE from the environment at startup, so getlocale() with no argument depends on the machine, while other categories stay 'C' until setlocale(). LC_ALL is not accepted (TypeError); read the composite value via setlocale(LC_ALL).
Examples
import locale
print(locale.getlocale()) # → ? ('ru_RU', 'UTF-8') — зависит от машины
print(locale.getlocale(locale.LC_NUMERIC)) # → (None, None) — это локаль C
locale.getlocale(locale.LC_ALL) # → TypeError: category LC_ALL is not supported
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy