On this page
typing.TextIO
Prev: typing.Text | Up: typing | Next: typing.TypeAliasType
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.TextIO
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import TextIO
Signature & Overview
typing.TextIO()
Typed approximation of the return of open() in text mode.
Methods & Attributes
TextIO.buffer(...)—TextIO.buffermethod/property.TextIO.close(self) -> None—TextIO.closemethod/property.TextIO.closed(...)—TextIO.closedmethod/property.TextIO.encoding(...)—TextIO.encodingmethod/property.TextIO.errors(...)—TextIO.errorsmethod/property.TextIO.fileno(self) -> int—TextIO.filenomethod/property.TextIO.flush(self) -> None—TextIO.flushmethod/property.TextIO.isatty(self) -> bool—TextIO.isattymethod/property.TextIO.line_buffering(...)—TextIO.line_bufferingmethod/property.TextIO.mode(...)—TextIO.modemethod/property.TextIO.name(...)—TextIO.namemethod/property.TextIO.newlines(...)—TextIO.newlinesmethod/property.TextIO.read(self, n: int = -1) -> ~AnyStr—TextIO.readmethod/property.TextIO.readable(self) -> bool—TextIO.readablemethod/property.TextIO.readline(self, limit: int = -1) -> ~AnyStr—TextIO.readlinemethod/property.TextIO.readlines(self, hint: int = -1) -> list[~AnyStr]—TextIO.readlinesmethod/property.TextIO.seek(self, offset: int, whence: int = 0) -> int—TextIO.seekmethod/property.TextIO.seekable(self) -> bool—TextIO.seekablemethod/property.TextIO.tell(self) -> int—TextIO.tellmethod/property.TextIO.truncate(self, size: int | None = None) -> int—TextIO.truncatemethod/property.TextIO.writable(self) -> bool—TextIO.writablemethod/property.TextIO.write(self, s: ~AnyStr) -> int—TextIO.writemethod/property.TextIO.writelines(self, lines: list[~AnyStr]) -> None—TextIO.writelinesmethod/property.
Usage
import io
from typing import TextIO
def first_line(fh: TextIO) -> str:
return fh.readline().strip()
assert first_line(io.StringIO("hello\nworld")) == "hello"
Gotchas
- Represents text streams (
str): Matchesopen(..., "r")andio.StringIO.
REPL Inspect
from typing import TextIO
help(TextIO)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/Text Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/TypeAliasType Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing