Memoryview Methods

memoryview.tolist()

Decode elements according to the view’s supported native element format and construct ordinary Python values. For a multidimensional view the result is nested in logical dimension order; for a zero-dimensional view CPython returns a scalar instead of a list. Unlike tobytes(), the method returns interpreted element values rather than raw representation bytes. Unsupported formats can raise NotImplementedError. The result is independent of subsequent buffer mutation.

Formal Syntax & Structure

python syntaxpython
view.tolist()

Return Value

list | scalar

Nested or flat list of values; scalar for a zero-dimensional view.

Working Example

Example Snippetpython
view = memoryview(b"ABCDEF").cast("B", [2, 3])print(view.tolist())print(memoryview(b"ABC").cast("c").tolist())print(memoryview(b"A").cast("B", ()).tolist())
Python Reference