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

memoryview

Prev: max | Up: __builtins__ | Next: min
Rel: bool, int, float, complex, str
Ref: docs.python.org — memoryview
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import memoryview

Overview & Signature

memoryview(object)

Create a new memoryview object which references the given object.

Common Methods & Attributes

Usage

buf = bytearray(b"abcdef")
with memoryview(buf) as view:
    sub = view[1:4]          # zero-copy slice!
    sub[0] = ord("B")
assert buf == b"aBcdef"

Gotchas

REPL Inspect

help(memoryview)

Linked from

Related notes