首页 > 编程语言 > 详细

Python 内置函数 memoryview

时间:2018-07-08 12:08:28      阅读:178      评论:0      收藏:0      [点我收藏+]

转载自:https://www.cnblogs.com/sesshoumaru/p/6035548.html

 

英文文档:

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 objobj 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‘
技术分享图片

Python 内置函数 memoryview

原文:https://www.cnblogs.com/yanxiatingyu/p/9279559.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!