inheritance
Duncan Booth
duncan at NOSPAMrcp.co.uk
Thu Jun 12 12:10:05 EDT 2003
"Duncan Smith" <buzzard at urubu.freeserve.co.uk> wrote in
news:bca77e$aq2$1 at newsg3.svr.pol.co.uk:
> Is there any alternative to explicitly overloading each of the parent
> class functions that return a new instance?
You could try creating an object of the appropriate type directly from
inside table.NumTable.__mul__
Something like:
def __mul__(self, other):
values, variables = ... calculate them ...
if issubclass(self, other):
resType = self.__class__
else:
resType = other.__class__
return resType(values, variables)
I don't know what you would do though if self and other are both subclasses
on NumTable but neither is a subclass of the other. To be correct you'ld
probably need to find the common base class.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list