summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2018-04-14 17:49:21 (GMT)
committerGitHub <noreply@github.com>2018-04-14 17:49:21 (GMT)
commit480ab05d5fee2b8fa161f799af33086a4e68c7dd (patch)
treeca45c39193fb970c4d300b27346a9dcf8aaac814 /Doc
parentb1dc07509f78b354e83f5f4a902f1ff80c7bb05d (diff)
downloadcpython-480ab05d5fee2b8fa161f799af33086a4e68c7dd.zip
cpython-480ab05d5fee2b8fa161f799af33086a4e68c7dd.tar.gz
cpython-480ab05d5fee2b8fa161f799af33086a4e68c7dd.tar.bz2
bpo-33176: Add a toreadonly() method to memoryviews. (GH-6466)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/stdtypes.rst19
1 files changed, 19 insertions, 0 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index a213189..af2b4e1 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -3591,6 +3591,25 @@ copying.
:mod:`struct` module syntax as well as multi-dimensional
representations.
+ .. method:: toreadonly()
+
+ Return a readonly version of the memoryview object. The original
+ memoryview object is unchanged. ::
+
+ >>> m = memoryview(bytearray(b'abc'))
+ >>> mm = m.toreadonly()
+ >>> mm.tolist()
+ [89, 98, 99]
+ >>> mm[0] = 42
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ TypeError: cannot modify read-only memory
+ >>> m[0] = 43
+ >>> mm.tolist()
+ [43, 98, 99]
+
+ .. versionadded:: 3.8
+
.. method:: release()
Release the underlying buffer exposed by the memoryview object. Many