use this on your Cython code: arg0 = arg0.encode(u"ascii")
Hopefully, this will work on both under a Py2 and Py3 runtime. On Sat, Apr 25, 2009 at 10:35 PM, [email protected] <[email protected]> wrote: > Hi, > > having issues with cython/python3 I found the thread > http://www.mail-archive.com/[email protected]/msg02346.html > > Actually, I have the same problem: > As *all* strings in cython code get converted to bytes, nothing works out. > > I my case I have a c function like: > > void foo(char *) > > cdef c_foo "foo"(char *) > > > cdef class A: > def __init__(self,arg0): > c_foo(arg0) > > > calling from python with > x = A('test') > > in python the argument 'test' is of type str, cython expects the > argument for c_foo to be of type bytes as char * is mapped to bytes. > > Now, as I do not want to change all calls to all functions which take > str arguments, I tried to convert 'test' from str to bytes. > > arg0 = arg0.encode("ascii") > > Result: > TypeError: encode() argument 1 must be string, not bytes. > > Even worse: > if isinstance(arg0, str): > > actually checks if arg0 is of type bytes ... > > Thats really bad, you can neither create nor recognize or convert > python3 str's in cython. > > > Maybe mapping "char *" to PyString_Type as a default for all internal > strings, and "unsigned char *" to PyBytes_Type? > > Any other suggestions? > > > MfG > Markus > > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
