Question Details

No question body available.

Tags

python

Answers (1)

Accepted Answer Available
Accepted Answer
February 16, 2026 Score: 12 Rep: 123,790 Quality: Expert Completeness: 80%

Per the docs:

Notice that spelling alternatives that only differ in case or use a hyphen instead of an underscore are also valid aliases because they are equivalent when normalized by normalizeencoding(). For example, 'utf-8' is a valid alias for the 'utf8' codec.

and:

Normalization works as follows: all non-alphanumeric characters except the dot used for Python package names are collapsed and replaced with a single underscore, leading and trailing underscores are removed. For example, ' -;#' becomes ''.

So 'utf-8' is normalized to 'utf8' which is in the aliases mapping:

>>> from encodings import normalize
encoding >>> from encodings.aliases import aliases >>> normalizeencoding("utf-8") 'utf8' >>> normalize_encoding("utf-8") in aliases.values() True