PyDocs

Nav

Generic Operating System Services

text_encoding

io

function · Added in 3.10
  • text_encoding(encoding, stacklevel=2, /)
A helper function to choose the text encoding.

When encoding is not None, this function returns it.
Otherwise, this function returns the default text encoding
(i.e. "locale" or "utf-8" depends on UTF-8 mode).

This function emits an EncodingWarning if encoding is None and
sys.flags.warn_default_encoding is true.

This can be used in APIs with an encoding=None parameter.
However, please consider using encoding="utf-8" for new APIs.
Changed in 3.11
  • 3.11: text_encoding() returns “utf-8” when UTF-8 mode is enabled and encoding is None.
0 Examples
No examples for io/text_encoding.
See Also
No see-alsos for io/text_encoding
0 Notes
No notes for text_encoding