我需要一个原始对象(字节)和这个对象减去 python 3 中的最后 20 个字节。我可以这样做:
b = a[0:-20]
但它复制了我的对象。我可以保存链接到对象的一部分的内存吗?
最佳答案
是的,使用 memoryview
:
b = memoryview(a)[:-20]
如文档所述:
memoryview
objects allow Python code to access the internal data of an object that supports the buffer protocol without copying.
关于python-3.x - 链接到python 3中字节对象的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23524191/