On this page
  1. locale.getencoding
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from locale import getencoding
help(getencoding)

Linked from

Related notes