我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用ctypes.pythonapi.PyObject_GetBuffer()。
def get_buffer(obj, writable=False): buf = Py_buffer() flags = PyBUF_WRITABLE if writable else PyBUF_SIMPLE PyObject_GetBuffer(py_object(obj), byref(buf), flags) try: buffer_type = c_char * buf.len return buffer_type.from_address(buf.buf) finally: PyBuffer_Release(byref(buf))