英文文檔:
class memoryview(obj)
-
memoryviewobjects allow Python code to access the internal data of an object that supports the buffer protocol without copying. -
Create a
memoryviewthat references obj. obj must support the buffer protocol. Built-in objects that support the buffer protocol includebytesandbytearray.
說明:
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'
