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