Python Glossary Русский

all Python 3Exceptionsexception

BufferError

built-in exceptions

A buffer-protocol operation is impossible (e.g. resizing a bytearray while a buffer is exported).

Syntax

raise BufferError

In practice it almost always means one thing: while a memoryview onto a bytearray is still alive, the buffer cannot be resized — append, extend, del and resize all fail. Wrapping the call in try/except is the wrong fix; release the view first with mv.release() or by dropping the last reference to it, and the buffer becomes resizable again.

Examples

try:
    raise BufferError
except BufferError as e:
    print(type(e).__name__)   # → BufferError

See also

Open in the full glossarydocs.python.orgReport an inaccuracy