I tried to convert void*
type in C to string
in python when using Cython to wrapper C language, but I don't know how to convert the void*
type to string
, when converting the C int
to python Py_ssize_t
, like(a part of a class):
cpdef int peek_tail(self):
cdef int value = <Py_ssize_t>cqueue.queue_peek_tail(self._c_queue)
When I want to convert it to string
, how can I define it?
cpdef ? peek_tail(self):
cdef ? value = <?>cqueue.queue_peek_tail(self._c_queue)
The ?
is what I want. Any documents exist?
You can use char*
on cdef
but since your using cpdef
you can just can also do str
for bytes (py2) or unicode (py3). I believe the queue_peek_tail
return is always Py_ssize_t
.
See here for more specfic info. Especially the line
Generally speaking: unless you know what you are doing, avoid using C strings where possible and use Python string objects instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.