On Mar 21, 7:48 pm, Martin Manns <[EMAIL PROTECTED]> wrote: > Hi, > > Is there a way to create a function that is equal to 0? > I try to redefine __cmp__ but I am pretty stuck. > > Something like: > > >>> def f(): return "" > ... > >>> # Some magic > >>> f == 0 > > True
Why do you want to do that? >>> class WhyOhWhy(object): ... def __init__(self, f): self.f = f ... def __call__(self, *args, **kwargs): return self.f(*args, **kwargs) ... def __eq__(self, other): return other == 0 ... >>> @WhyOhWhy ... def f(x): print "Why oh why,", x ... >>> f("do this?") Why oh why, do this? >>> f == 0 True >>> -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list