ctypes buffer modification
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.
精彩评论