locale.getpreferredencoding
Prev: locale.getlocale | Up: locale | Next: locale.localeconv
Rel: locale.atof, locale.atoi, locale.currency, locale.Error
Ref: docs.python.org — locale.getpreferredencoding
Tags: #public #python3 #stdlib #locale
Import
import locale
from locale import getpreferredencoding
Signature & Overview
locale.getpreferredencoding(do_setlocale=True)
Return the charset that the user is likely using, according to the system configuration.
Usage
import locale
enc = locale.getpreferredencoding(do_setlocale=False)
assert isinstance(enc, str) and len(enc) > 0
Gotchas
- Pass
do_setlocale=Falsein multi-threaded code so it never mutates global locale state.
REPL Inspect
from locale import getpreferredencoding
help(getpreferredencoding)
Linked from
Related notes
- tuts/python3/stdlib_module/locale/getlocale Linked here; links to this page; shared tags: #locale, #stdlib
- tuts/python3/stdlib_module/locale/localeconv 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