On this page
io.text_encoding
Prev: io.StringIO | Up: io | Next: io.TextIOBase
Rel: io.BlockingIOError, io.BufferedIOBase, io.BufferedRandom, io.BufferedReader
Ref: docs.python.org — io.text_encoding
Tags: #public #python3 #stdlib #io
Import
import io
from io import text_encoding
Signature & Overview
io.text_encoding(encoding, stacklevel=2, /)
A helper function to choose the text encoding.
Usage
import io
assert io.text_encoding(None) == "locale"
assert io.text_encoding("utf-8") == "utf-8"
Gotchas
- Python 3.10+ helper for library authors: Forward
encoding=io.text_encoding(encoding)in wrapper functions aroundopen()soPYTHONWARNDEFAULTENCODING(-X warn_default_encoding) warns at the right call site.
REPL Inspect
from io import text_encoding
help(text_encoding)
Linked from
Related notes
- tuts/python3/stdlib_module/io/StringIO Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/TextIOBase Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/io/BlockingIOError Linked here; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BufferedIOBase Linked here; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BufferedRandom Linked here; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BufferedReader Linked here; shared tags: #io, #stdlib
- tuts/c/stdlib/stdio_and_file_io shared tags: #io, #stdlib
- tuts/cpp/stdlib/io_and_filesystem shared tags: #io, #stdlib
- tuts/cpp/stdlib/io_and_filesystem/format_and_print shared tags: #io, #stdlib