Python memoryview() Function
Description
memoryview() The function returns a memory view object of the given argument.
A memory view object wraps data that supports the buffer protocol, allowing Python code to access it without copying the object.
Syntax
memoryview syntax:
memoryview(obj)
Parameter Description:
- obj -- the object
Return Value
Returns a list of tuples.
Example
The following examples demonstrate how to use memoryview:
Python 2.x application:
v
=
memoryview
(
'
abcefg
'
)
v
[
1
]
'
b
'
v
[
1
]
'
g
'
v
[
1
:
4
]
<
memory
at
0
x77ab28
v
[
1
:
4
]
.
tobytes
(
)
'
bce
'
Python 3.x application:
v
=
memoryview
(
bytearray
(
"
abcefg
"
,
'
utf-8
'
)
)
(
v
[
1
]
)
98
(
v
[
1
]
)
103
(
v
[
1
:
4
]
)
<
memory
at
0
x10f543a08
(
v
[
1
:
4
]
.
tobytes
(
)
)
b
'
bce
'
Python built-in function