access string data from within cython

Diez B. Roggisch deets at
Wed Aug 5 23:22:56 CEST 2009

sturlamolden schrieb:
> On 5 Aug, 19:16, "Diez B. Roggisch" <de... at> wrote:
>> void foo(void *data, size_t length)
>> The wrapper is supposed to be called with a python (byte)string instance,
>> which might contain more than one '\0'-character.
>> So how do I access the raw data of a string?
> cdef extern void foo(void *data, int length)
> cdef char *data
> cdef int length
> bytestring = ... #whatever
> rawdata = <char *> bytestring
> length = <int> len(bytestring)

And that gives me the *full* bytestring, not only until the first zero? 
I can't try that right now (not at work anymore), but if it's that easy, 
that would be great.


More information about the Python-list mailing list