On this page
io.TextIOWrapper
Prev: io.TextIOBase | Up: io | Next: io.UnsupportedOperation
Rel: io.BlockingIOError, io.BufferedIOBase, io.BufferedRandom, io.BufferedReader
Ref: docs.python.org — io.TextIOWrapper
Tags: #public #python3 #stdlib #io
Import
import io
from io import TextIOWrapper
Signature & Overview
io.TextIOWrapper(buffer, encoding=None, errors=None, newline=None, line_buffering=False, write_through=False)
Character and line based layer over a BufferedIOBase object, buffer.
Methods & Attributes
TextIOWrapper.close(self, /)—TextIOWrapper.closemethod/property.TextIOWrapper.detach(self, /)—TextIOWrapper.detachmethod/property.TextIOWrapper.fileno(self, /)—TextIOWrapper.filenomethod/property.TextIOWrapper.flush(self, /)—TextIOWrapper.flushmethod/property.TextIOWrapper.isatty(self, /)—TextIOWrapper.isattymethod/property.TextIOWrapper.read(self, size=-1, /)—TextIOWrapper.readmethod/property.TextIOWrapper.readable(self, /)—TextIOWrapper.readablemethod/property.TextIOWrapper.readline(self, size=-1, /)—TextIOWrapper.readlinemethod/property.TextIOWrapper.readlines(self, hint=-1, /)— Return a list of lines from the stream.TextIOWrapper.reconfigure(self, /, *, encoding=None, errors=None, newline=None, line_buffering=None, write_through=None)— Reconfigure the text stream with new parameters.TextIOWrapper.seek(self, cookie, whence=0, /)— Set the stream position, and return the new stream position.TextIOWrapper.seekable(self, /)—TextIOWrapper.seekablemethod/property.TextIOWrapper.tell(self, /)— Return the stream position as an opaque number.TextIOWrapper.truncate(self, pos=None, /)—TextIOWrapper.truncatemethod/property.TextIOWrapper.writable(self, /)—TextIOWrapper.writablemethod/property.TextIOWrapper.write(self, text, /)—TextIOWrapper.writemethod/property.TextIOWrapper.writelines(self, lines, /)— Write a list of lines to stream.
Usage
import io
raw = io.BytesIO("café\n".encode("utf-8"))
text = io.TextIOWrapper(raw, encoding="utf-8")
assert text.read() == "café\n"
text.detach() # release raw without closing it
assert not raw.closed
Gotchas
- Closing
TextIOWrappercloses its underlying binary stream: Callwrapper.detach()first if you need to keep the wrappedBytesIOor socket open. - Supports
reconfigure(encoding=..., errors=...): Handy for changingsys.stdoutencoding at runtime.
REPL Inspect
from io import TextIOWrapper
help(TextIOWrapper)
Linked from
Related notes
- tuts/python3/stdlib_module/io/TextIOBase Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/UnsupportedOperation 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