How can I make a function equal to 0?

attn.steven.kuo at gmail.com attn.steven.kuo at gmail.com
Fri Mar 21 16:10:03 EDT 2008


On Mar 21, 12:48 pm, Martin Manns <mma... at gmx.net> 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
>


You would have to bind f (the name)
to 0 (or False).  You can "cheat"
and use a decorator:

>>> def makezero(f): return 0

>>> @makezero
... def f(): return 1

>>> f == 0
True

--
Hope this helps,
Steven



More information about the Python-list mailing list