Martin Manns wrote: > 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 > > Thanks in advance > > Martin
Use a callable object: >>> class F(object): ... def __cmp__(self, other): return cmp(other, 0) ... def __call__(self): return "" ... >>> f = F() >>> f() '' >>> f == 0 True Peter -- http://mail.python.org/mailman/listinfo/python-list