Python内置函数(42)——memoryview


英文文档:

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'

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM