On this page
io.BufferedRandom
Prev: io.BufferedIOBase | Up: io | Next: io.BufferedReader
Rel: io.BlockingIOError, io.BufferedIOBase, io.BufferedReader, io.BufferedRWPair
Ref: docs.python.org — io.BufferedRandom
Tags: #public #python3 #stdlib #io
Import
import io
from io import BufferedRandom
Signature & Overview
io.BufferedRandom(raw, buffer_size=131072)
A buffered interface to random access streams.
Methods & Attributes
BufferedRandom.close(self, /)—BufferedRandom.closemethod/property.BufferedRandom.detach(self, /)—BufferedRandom.detachmethod/property.BufferedRandom.fileno(self, /)—BufferedRandom.filenomethod/property.BufferedRandom.flush(self, /)—BufferedRandom.flushmethod/property.BufferedRandom.isatty(self, /)—BufferedRandom.isattymethod/property.BufferedRandom.peek(self, size=0, /)—BufferedRandom.peekmethod/property.BufferedRandom.read(self, size=-1, /)—BufferedRandom.readmethod/property.BufferedRandom.read1(self, size=-1, /)—BufferedRandom.read1method/property.BufferedRandom.readable(self, /)—BufferedRandom.readablemethod/property.BufferedRandom.readinto(self, buffer, /)—BufferedRandom.readintomethod/property.BufferedRandom.readinto1(self, buffer, /)—BufferedRandom.readinto1method/property.BufferedRandom.readline(self, size=-1, /)—BufferedRandom.readlinemethod/property.BufferedRandom.readlines(self, hint=-1, /)— Return a list of lines from the stream.BufferedRandom.seek(self, target, whence=0, /)—BufferedRandom.seekmethod/property.BufferedRandom.seekable(self, /)—BufferedRandom.seekablemethod/property.BufferedRandom.tell(self, /)—BufferedRandom.tellmethod/property.BufferedRandom.truncate(self, pos=None, /)—BufferedRandom.truncatemethod/property.BufferedRandom.writable(self, /)—BufferedRandom.writablemethod/property.BufferedRandom.write(self, buffer, /)—BufferedRandom.writemethod/property.BufferedRandom.writelines(self, lines, /)— Write a list of lines to stream.
Usage
import io
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "rw.bin"
with open(p, "w+b") as f:
assert isinstance(f, io.BufferedRandom)
f.write(b"hello")
f.seek(0)
assert f.read() == b"hello"
Gotchas
- Returned automatically by
open(..., "r+b")/"w+b": Supports buffered reading, writing, and random seeking on a single seekable binary stream.
REPL Inspect
from io import BufferedRandom
help(BufferedRandom)
Linked from
- tuts/python3/stdlib_module/io
- tuts/python3/stdlib_module/io/BlockingIOError
- tuts/python3/stdlib_module/io/BufferedIOBase
- tuts/python3/stdlib_module/io/BufferedReader
- tuts/python3/stdlib_module/io/BufferedRWPair
- tuts/python3/stdlib_module/io/BufferedWriter
- tuts/python3/stdlib_module/io/BytesIO
- tuts/python3/stdlib_module/io/FileIO
- tuts/python3/stdlib_module/io/IncrementalNewlineDecoder
- tuts/python3/stdlib_module/io/IOBase
- tuts/python3/stdlib_module/io/open
- tuts/python3/stdlib_module/io/open_code
- tuts/python3/stdlib_module/io/RawIOBase
- tuts/python3/stdlib_module/io/Reader
- tuts/python3/stdlib_module/io/StringIO
- tuts/python3/stdlib_module/io/text_encoding
- tuts/python3/stdlib_module/io/TextIOBase
- tuts/python3/stdlib_module/io/TextIOWrapper
- tuts/python3/stdlib_module/io/UnsupportedOperation
- tuts/python3/stdlib_module/io/Writer
Related notes
- tuts/python3/stdlib_module/io/BlockingIOError Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BufferedIOBase Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BufferedReader Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BufferedRWPair Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/io/BufferedWriter links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BytesIO links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/FileIO links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/IncrementalNewlineDecoder links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/IOBase links to this page; shared tags: #io, #stdlib