[Numpy-discussion] Multiple inheritance from ndarray

Stefan van der Walt stefan at sun.ac.za
Thu Feb 23 02:47:04 CST 2006


On Wed, Feb 22, 2006 at 08:58:28PM -0700, Travis Oliphant wrote:
> Here's an outline of what you need to do.  This is, of course, 
> untested....  For example, I don't really know what actImage is.
> 
> from numpy import ndarray, array
> 
> class Image(ndarray, actImage):
>    def __new__(subtype, *args)
>        act1 = actImage.__new__(actImage, *args)
>        actImage.__init__(act1, *args)
>        arr = array(act1.getArray(), 'd', copy=False)
>        self = arr.view(subtype)
>        # you might need to copy attributes from act1 over to self here...
>        return self

This is probably the right place to use super, i.e.:

def __new__(subtype, *args):
	act1 = super(Image, subtype).__new__(subtype, *args)
	...

def __init__(self, *args):
	super(Image, self).__init__(*args)

The attached script shows how multiple inheritance runs through
different classes.

Stéfan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inh.py
Type: text/x-python
Size: 855 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060223/e8afe97f/attachment-0001.py 


More information about the Numpy-discussion mailing list