Uwe Schmitt wrote:
> Hi,
>
> I'm trying to wrap an existing C entension as follows:
>
>     cdef struct A:
>         double * values
>         int n
>
>
>     cdef class Test:
>         cdef A a
>
>         @classmethod
>         def buildFromData(cls, filename):
>
>             cdef A a # = foofoo(filename)
>
>             obj = cls()
>             obj.a = a
>             return obj
>
> Running Cython the "obj.a=a" results in """Cannot convert 'A' to Python
> object""".

Because "obj.a" is an attribute of the Python object "obj", while a is a C
struct...

I.e. you need to type "cdef Test obj = cls()" instead, so that it is known
compile-time that "obj" will be an instance of Test and thus have a typed
"a" field.

(I don't know myself whether classmethod works as intended for cdef
classes either, but this should be one obstacle less...)

Dag Sverre


_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to