PyDocs

Nav

Python Runtime Services

memoryview.cast

builtins

method of memoryview · Added in 3.3
  • memoryview.cast(format, /)
  • memoryview.cast(format, shape, /)
Cast a memoryview to a new format or shape.
Changed in 3.5
  • 3.5: The source format is no longer restricted when casting to a byte view.
1 Example
>>> import array
>>> a = array.array('l', [1,2,3])
>>> x = memoryview(a)
>>> x.format
'l'
>>> x.itemsize
8
>>> len(x)
3
>>> x.nbytes
24
>>> y = x.cast('B')
>>> y.format
'B'
>>> y.itemsize
1
>>> len(y)
24
>>> y.nbytes
24
from the Python docs
See Also
No see-alsos for builtins/memoryview.cast
0 Notes
No notes for memoryview.cast