new python syntax: concatenation of functions
Sagiv Malihi
malihi1 at 012.net.il
Thu Mar 11 09:52:05 EST 2004
what you would *really* like to do, is to be able to extend any class, and
override it's operators.
in your example, you would like to do something like:
def mul_funcs(self, other):
def temp(*args, **kw):
return self(other(*args, **kw))
return temp
and then:
FunctionType.__mul__(self, other) = mul_funcs
"Daniel Dittmar" <daniel.dittmar at sap.com> wrote in message
news:c2pnju$2t4$1 at news1.wdf.sap-ag.de...
> Radovan Garabik wrote:
> > or, without leaving ascii:
> >
> > def (x)composition(y):
> > return lambda par: x(y(par))
> > print (a composition b)(x)
>
> or without leaving Python
>
> class Composition:
> def __init__ (self, outer, inner):
> self.outer = outer
> self.inner = inner
>
> def __call__ (self, *args):
> return self.outer (self.inner (*args))
>
> def __str__ (self):
> return '%s ° %s' % (self.outer, self.inner)
>
> Daniel
>
>
>
More information about the Python-list
mailing list