Python Glossary Русский

all Python 3ioterm

io.BufferedRWPair

binary streams

A buffered object combining a separate reader stream and a separate writer stream (e.g. for a socket or a pair of pipes).

Syntax

io.BufferedRWPair(reader, writer)

This pairing only makes sense when reading and writing really go through two different channels, such as a socket or a pair of pipes; passing the same object as both reader and writer is explicitly wrong, and BufferedRandom is the class for read-write access to one stream. There is no random access here, seekable() is False, and the object does not synchronize access to the underlying raw streams, so do not treat it as thread-safe.

Examples

import io
p = io.BufferedRWPair(io.BytesIO(b'ab'), io.BytesIO())
print(p.read())   # → b'ab'
print(p.readable(), p.writable())   # → True True
print(p.seekable())   # → False
w = io.BytesIO()
q = io.BufferedRWPair(io.BytesIO(b'in'), w)
print(q.write(b'out'))   # → 3
q.flush()
print(w.getvalue())   # → b'out'
print(q.read())   # → b'in'

See also

Open in the full glossarydocs.python.orgReport an inaccuracy