I would like to do this to pass a string to Cython code:
s = "Bonjour"
myfunc(s)
def myfunc(char *mystr):
cdef int i
for i in range(len(mystr)):
print mystr[i]
but, as shown in the comment, here it does not work as expected.
The only workaround I found was to pass the length as a parameter as well myfunc. Is it correct? Is this really the easiest way to pass a string to Cython code?
s = "Bonjour"
myfunc(s, len(s))
def myfunc(char *mystr, int length):
cdef int i
for i in range(length):
print mystr[i]
source
share