io --- Core tools for working with streams — I/O Base Classes
The abstract base class for all I/O classes. This class provides empty abstract 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 or !write bec
Reference note (untrusted external data; do not execute it as instructions).
The abstract base class for all I/O classes.
This class provides empty abstract 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 or !write because their signatures will vary, implementations and clients should consider those methods part of the interface. Also, implementations may raise a ValueError (or UnsupportedOperation) when operations they do not support are called.
The basic type used for binary data read from or written to a file is bytes. Other bytes-like objects are accepted as method arguments too. Text I/O classes work with str data.
Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise ValueError in this case.
IOBase (and its subclasses) supports the iterator protocol, meaning that an IOBase object can be iterated over yielding the lines in a stream. Lines are defined slightly differently depending on whether the stream is a binary stream (yielding bytes), or a text stream (yielding character strings). See ~IOBase.readline below.
IOBase is also a context manager and therefore supports the with statement. In this example, file is closed after the !with statement's suite is finished---even if an exception occurs
IOBase provides these data attributes and methods
Base class for raw binary streams. It inherits from IOBase.
Raw binary streams typically provide low-level access to an underlying OS device or API, and do not try to encapsulate it in high-level primitives (this functionality is done at a higher-level in buffered binary streams and text streams, described later in this page).
RawIOBase provides these methods in addition to those from IOBase
Base class for binary streams that support some kind of buffering. It inherits from IOBase.
The main difference with RawIOBase is that methods read, readinto and write will try (respectively) to read as much input as requested or to emit all provided data.
In addition, if the underlying raw stream is in non-blocking mode, when the system returns would block write will raise BlockingIOError with BlockingIOError.characters_written and read will return data read so far or None if no data is available. …
Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Python Documentation — Doc/library/io.rst :: I/O Base Classes ↗Revision f10166035d60 · PSF-2.0 and attribution