开发者

ctypes buffer modification

开发者 https://www.devze.com 2022-12-23 06:35 出处:网络
I need to call a c library from my python code.The c library does a lot of image manipulation, so I am passing it image buffers allocated using create_string_buffer.

I need to call a c library from my python code. The c library does a lot of image manipulation, so I am passing it image buffers allocated using create_string_buffer.

The problem is that I also need to manipulate and change these bu开发者_如何转开发ffers. What is the best way to reach in and twiddle individual values in my buffers? The buffers are all uint8 buffers.


You mean, something like...:

>>> import ctypes
>>> x = ctypes.create_string_buffer('howdy!')
>>> x.value
'howdy!'
>>> x[0] = 'C'
>>> x.value
'Cowdy!'

...?


You may find that Cython is a lot nicer then the ctypes module for melding C libraries with Python code.

0

精彩评论

暂无评论...
验证码 换一张
取 消