io.IOBase
Prev: io.IncrementalNewlineDecoder | Up: io | Next: io.open
Rel: io.BlockingIOError, io.BufferedIOBase, io.BufferedRandom, io.BufferedReader
Ref: docs.python.org — io.IOBase
Tags: #public #python3 #stdlib #io
Import
import io
from io import IOBase
Signature & Overview
io.IOBase()
The abstract base class for all I/O classes.
Methods & Attributes
IOBase.close(self, /)— Flush and close the IO object.IOBase.fileno(self, /)— Return underlying file descriptor if one exists.IOBase.flush(self, /)— Flush write buffers, if applicable.IOBase.isatty(self, /)— Return whether this is an 'interactive' stream.IOBase.readable(self, /)— Return whether object was opened for reading.IOBase.readline(self, size=-1, /)— Read and return a line from the stream.IOBase.readlines(self, hint=-1, /)— Return a list of lines from the stream.IOBase.seek(self, offset, whence=0, /)— Change the stream position to the given byte offset.IOBase.seekable(self, /)— Return whether object supports random access.IOBase.tell(self, /)— Return current stream position.IOBase.truncate(self, size=None, /)— Truncate file to size bytes.IOBase.writable(self, /)— Return whether object was opened for writing.IOBase.writelines(self, lines, /)— Write a list of lines to stream.
Usage
import io
assert isinstance(io.StringIO(), io.IOBase)
assert isinstance(io.BytesIO(), io.IOBase)
Gotchas
- Root abstract base class for all streams: Defines context-manager support (
__enter__/__exit__), iteration over lines,close(), andclosed.
REPL Inspect
from io import IOBase
help(IOBase)
Linked from
Related notes
- tuts/python3/stdlib_module/io/IncrementalNewlineDecoder Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/open 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