Re: dealing with objects of 2 classes
Stefan Behnel <[email protected]> Mon, 15 Jun 2009 06:23:00 +0200
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
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 =3D extern_func1() > = > cdef class b: > cdef foobar_t *_foobar > def __init__(self, obja): > self._foobar =3D obja.foo > = > cdef class c: > def __init__(self, obja): > self._foobar =3D 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 =3D 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