|
From: Barry S. <ba...@ba...> - 2010-04-12 21:26:26
|
On 10 Apr 2010, at 19:34, Fernando Libonati wrote:
> In cxx_extensions.cxx
>
> extern "C" PyObject *getattro_handler( PyObject *self, PyObject *name )
> {
> try
> {
> PythonExtensionBase *p = getPythonExtensionBase( self );
> return new_reference_to( p->getattro( Py::String( name ) ) );
> }
> catch( Py::Exception &)
> {
> return NULL; // indicate error
> }
> }
>
> In a derived class this always call the getattro of the base class, and never get the derived class attributes visible.
> How can I access a derived class attro?
>
> I've attached the test system, base.h and base.cxx.
> When compiled, it is possible to create a g = base.Gain("b",1,None,2.43) object, and access name,number and parent attributes, but doesn't reach the gain attribute.
> Python says
> """Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'Gain' object has no attribute 'gain'
> """
>
> It would be possible to call first the derived class method, and inside it call the base class method (under the user responsibility)?
You cannot use C++ derivation to create a set of Python types.
When Block is setup there are a lot of python data structures created and initialise to make Block available to Python.
Gain has none of these python data structures.
If you want a hierarchy of classes then only the leafs can be turned into Python classes.
Barry
|