Rich comparison in derived class, but not in base (boost.python)
Alex Martelli
aleaxit at yahoo.com
Wed Mar 21 10:54:13 EST 2001
"Pearu Peterson" <pearu at cens.ioc.ee> wrote in message
news:Pine.LNX.4.21.0103211112040.1131-100000 at kev.ioc.ee...
[snip]
> I checked also the following approach:
> class expr:
> def __init__(self,*args):
> self.e = ex(*args)
> def __cmp__(self,other):
> raise NotImplementedError,"expr.__cmp__() should not be called"
> def __lt__(self, other):
> return relational(self.e, other, '<')
> # also other richcomp methods are defined but not shown here
>
> that works fine but then I would have to re-define also all `ex' methods
> in `expr' --- there are more than 30 of them, so I would not want to do
As a temporary workaround, just delegate via __getattr__:
def __getattr__(self, attr):
return getattr(self.e, attr)
Alex
More information about the Python-list
mailing list