网络编程
位置:首页>> 网络编程>> Python编程>> Python 内置函数memoryview(obj)的具体用法

Python 内置函数memoryview(obj)的具体用法

作者:十月狐狸  发布时间:2023-03-20 14:40:58 

标签:Python,memoryview

memoryview() 函数返回给定参数的内存查看对象(Momory view)。

语法

memoryview 语法:memoryview(obj)

参数说明:obj -- 对象

返回值:返回元组列表。

英文文档:

class memoryview(obj)

memoryview objects allow Python code to access the internal data of an object that supports the buffer protocol without copying.
Create a memoryview that references obj. obj must support the buffer protocol. Built-in objects that support the buffer protocol include bytes and bytearray.

说明:

1. 函数功能返回内存查看对象,实际上是内存查看对象(Momory view)的构造函数。

2. 所谓内存查看对象,是指对支持缓冲区协议的数据进行包装,在不需要复制对象基础上允许Python代码访问。

3. Python内置对象中支持缓冲区协议的对象有bytes和bytearray。

示例


>>> v = memoryview(b'abcefg')
>>> v[1]
98
>>> v[-1]
103
>>> v[1:4]
<memory at 0x7f3ddc9f4350>
>>> bytes(v[1:4])
b'bce'

来源:https://www.cnblogs.com/sesshoumaru/p/6035548.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com