ID EN
IO

text_encoding

Python 3.11

This is a helper function for callables that use open() or TextIOWrapper and have an encoding=None parameter.

Syntax

PYTHON
io.text_encoding(encoding, stacklevel=2, /)

Examples

Example 1
PYTHON
def read_text(path, encoding=None):
    encoding = io.text_encoding(encoding)   stacklevel=2
    with open(path, encoding) as f:
        return f.read()

See Also

open() TextIOWrapper UTF-8 Mode EncodingWarning sys.flags.warn_default_encoding EncodingWarning Text Encoding text_encoding()