Re: dealing with objects of 2 classes

"Stefan Behnel" <[email protected]> Mon, 15 Jun 2009 08:23:35 +0200 (CEST)
Newsgroups gmane.comp.python.pyrex
Message-ID <037fd2f284775eec041d0182bc294ca2.squirrel@groupware.dvs.informatik.tu-darmstadt.de>
Bartosz SKOWRON wrote:
> On Mon, Jun 15, 2009 at 5:23 AM, Stefan Behnel<[email protected]> wrote:
>
>>> when i create new object of class b, `b(a())` =C2=A0i get:
>>> AttributeError: 'a' object has no attribute 'foo'
>>>
>>> when i create new object of class c, `c(a())` =C2=A0i get:
>>> AttributeError: 'c' object has no attribute '_foobar'
>>
>> You have to declare the variables that you assign the objects to, as in
>>
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0cdef b some_b
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0some_b =3D b(a())
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0print some_b.foo.some_struct_member
>
> but that b(a()) I would like to do from the Python interpreter, not in
> Pyrex.

Ah, ok. Then read the doc section on extension type attributes:

http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/version/Doc/Manual=
/extension_types.html#ExtTypeAttrs

Stefan