22 Jul
2010
22 Jul
'10
6:49 a.m.
Thought about it some more. Here’s a more general formula: class InfixArity(object): def __init__(self, arity): self.arity = arity self.args = [] def __call__(self, func): self.func = func return self def __add__(self, arg): self.args.append(arg) if len(self.args) < self.arity: return self else: return self.func(*self.args) __radd__ = __add__ Infix = lambda func: InfixArity(2)(func) And of course, one can use __mul__ or __div__ or whatever to taste. "1 // add // 2” doesn’t make me instantly vomit in my mouth. ;-) -- Carl Johnson