all Python 3ioterm
io.IOBase
abstract bases
The abstract base class of all I/O streams (files and StringIO/BytesIO); it defines the shared close/readable/writable/seekable interface.
Syntax
issubclass(cls, io.IOBase)
isinstance(obj, io.IOBase) only confirms that something is a stream, not that it can be read or written: read() and write() are introduced by subclasses, while IOBase itself provides close(), with-statement support and the readable()/writable()/seekable() queries. Touching an already closed stream raises ValueError about an I/O operation on a closed file, not OSError — catch ValueError.
Examples
import io
print(issubclass(io.RawIOBase, io.IOBase)) # → True
print(isinstance(io.StringIO(), io.IOBase)) # → True
print(issubclass(io.TextIOBase, io.IOBase)) # → True
s = io.StringIO('abc')
print(s.readable(), s.writable(), s.seekable()) # → True True True
s.close()
print(s.closed) # → True
print(s.read()) # → ValueError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy