ID EN
IO

BytesIO

Python 3.11

A binary stream using an in-memory bytes buffer. It inherits from BufferedIOBase. The buffer is discarded when the close() method is called.

Syntax

PYTHON
class io.BytesIO(initial_bytes=b'')

Examples

Example 1
PYTHON
>>> b = io.BytesIO(b"abcdef")
>>> view = b.getbuffer()
>>> view[2:4] = b"56"
>>> b.getvalue()
b'ab56ef'

See Also

BufferedIOBase close() bytes-like object BytesIO BufferedIOBase IOBase BytesIO bytes