io.IOBase

class io.IOBase[source]

The abstract base class for all I/O classes, acting on streams of bytes. There is no public constructor.

This class provides dummy implementations for many methods that derived classes can override selectively; the default implementations represent a file that cannot be read, written or seeked.

Even though IOBase does not declare read, readinto, or write because their signatures will vary, implementations and clients should consider those methods part of the interface. Also, implementations may raise a IOError when operations they do not support are called.

The basic type used for binary data read from or written to a file is the bytes type. Method arguments may also be bytearray or memoryview of arrays of bytes. In some cases, such as readinto, a writable object such as bytearray is required. Text I/O classes work with unicode data.

Note that calling any method (except additional calls to close(), which are ignored) on a closed stream should raise a ValueError.

IOBase (and its subclasses) support the iterator protocol, meaning that an IOBase object can be iterated over yielding the lines in a stream.

IOBase also supports the with statement. In this example, fp is closed after the suite of the with statement is complete:

with open(‘spam.txt’, ‘r’) as fp:
fp.write(‘Spam and eggs!’)

Methods

__enter__
__exit__
__format__ default object formatter
__new__((S, ...)
__reduce__ helper for pickle
__reduce_ex__ helper for pickle
__sizeof__(() -> int) size of object in memory, in bytes
__subclasshook__ Abstract classes can override this to customize issubclass().
_checkClosed
_checkReadable
_checkSeekable
_checkWritable
close Flush and close the IO object.
fileno Returns underlying file descriptor if one exists.
flush Flush write buffers, if applicable.
isatty Return whether this is an ‘interactive’ stream.
readable Return whether object was opened for reading.
readline Read and return a line from the stream.
readlines Return a list of lines from the stream.
seek Change stream position.
seekable Return whether object supports random access.
tell Return current stream position.
truncate Truncate file to size bytes.
writable Return whether object was opened for writing.
writelines

Attributes

closed
next