How can I make a function equal to 0?
__peter__ at web.de
Fri Mar 21 21:04:28 CET 2008
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
> Thanks in advance
Use a callable object:
>>> class F(object):
... def __cmp__(self, other): return cmp(other, 0)
... def __call__(self): return ""
>>> f = F()
>>> f == 0
More information about the Python-list