Questions tagged «memoryview»

5
Python中的memoryview的确切含义是什么
查看memoryview上的文档: memoryview对象允许Python代码无需复制即可访问支持缓冲区协议的对象的内部数据。 类memoryview(obj) 创建引用obj的memoryview。obj必须支持缓冲区协议。支持缓冲区协议的内置对象包括字节和字节数组。 然后我们得到了示例代码: >>> v = memoryview(b'abcefg') >>> v[1] 98 >>> v[-1] 103 >>> v[1:4] <memory at 0x7f3ddc9f4350> >>> bytes(v[1:4]) b'bce' 报价结束,现在让我们仔细看看: >>> b = b'long bytes stream' >>> b.startswith(b'long') True >>> v = memoryview(b) >>> vsub = v[5:] >>> vsub.startswith(b'bytes') Traceback (most recent call last): File "<stdin>", …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.