[Pyrex] dealing with objects of 2 classes
Stefan Behnel
stefan_ml at behnel.de
Mon Jun 15 06:23:00 CEST 2009
Bartosz SKOWRON wrote:
> I have a new problem which I cannot find a solution.
>
> Here is a very simple example:
>
> cdef class a:
> cdef foobar_t *foo
> def __init__(self):
> self.foo = extern_func1()
>
> cdef class b:
> cdef foobar_t *_foobar
> def __init__(self, obja):
> self._foobar = obja.foo
>
> cdef class c:
> def __init__(self, obja):
> self._foobar = obja
>
>
> when i create new object of class b, `b(a())` i get:
> AttributeError: 'a' object has no attribute 'foo'
>
> when i create new object of class c, `c(a())` i get:
> AttributeError: 'c' object has no attribute '_foobar'
You have to declare the variables that you assign the objects to, as in
cdef b some_b
some_b = b(a())
print some_b.foo.some_struct_member
Otherwise, Pyrex cannot know what type they have, and that this type has
the above attributes.
Stefan
More information about the Pyrex
mailing list