Python io Module
Example
Use an in-memory bytes buffer:
import io
b = io.BytesIO()
b.write(b"Emil")
b.seek(0)
print(b.read())
Try it Yourself »
Definition and Usage
The io module provides Python’s main facilities for dealing with streams (text, binary, buffered).
Use it to work with files and in-memory streams via high-level classes like TextIOWrapper, BytesIO, and StringIO.
Members
Member | Description |
---|---|
BufferedRandom | Buffered interface to random access binary streams. |
BufferedReader | Buffered interface for reading from a raw stream. |
BufferedWriter | Buffered interface for writing to a raw stream. |
BytesIO | In-memory stream for binary data. |
FileIO | Raw binary I/O to OS-level file descriptors. |
IOBase | Abstract base class for all I/O classes. |
open() | Open a file and return a file object (alias of built-in open). |
RawIOBase | Abstract base class for raw binary I/O. |
StringIO | In-memory stream for text data. |
TextIOWrapper | Buffered text interface to a buffered raw stream. |