On this page
locale.getencoding
Prev: locale.getdefaultlocale | Up: locale | Next: locale.getlocale
Rel: locale.atof, locale.atoi, locale.currency, locale.Error
Ref: docs.python.org — locale.getencoding
Tags: #public #python3 #stdlib #locale
Import
import locale
from locale import getencoding
Signature & Overview
locale.getencoding()
Get the current locale encoding.
Usage
import locale
# Python 3.11+: returns the current locale encoding without invoking setlocale()
enc = locale.getencoding() if hasattr(locale, "getencoding") else locale.getpreferredencoding(False)
assert isinstance(enc, str) and len(enc) > 0
Gotchas
- Requires Python 3.11+: Preferred over
getpreferredencoding()because it doesn't inspect UTF-8 Mode or callsetlocale().
REPL Inspect
from locale import getencoding
help(getencoding)
Linked from
Related notes
- tuts/python3/stdlib_module/locale/getdefaultlocale Linked here; links to this page; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/getlocale 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/getpreferredencoding shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/localeconv shared tags: #locale, #stdlib