On this page
  1. io.BytesIO
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

io.BytesIO

Prev: io.BufferedWriter | Up: io | Next: io.FileIO
Rel: io.BlockingIOError, io.BufferedIOBase, io.BufferedRandom, io.BufferedReader
Ref: docs.python.org — io.BytesIO
Tags: #public #python3 #stdlib #io


Import

import io
from io import BytesIO

Signature & Overview

io.BytesIO(initial_bytes=b'')

Buffered I/O implementation using an in-memory bytes buffer.

Methods & Attributes

Usage

import io

buf = io.BytesIO()
buf.write(b"hello ")
buf.write(b"bytes")
assert buf.getvalue() == b"hello bytes"

buf.seek(0)
assert buf.read(5) == b"hello"

Gotchas

REPL Inspect

from io import BytesIO
help(BytesIO)

Linked from

Related notes