Proto-PEP: Overloadable Boolean Operators
Michael Hudson
mwh at python.net
Mon Sep 6 07:14:12 EDT 2004
aleaxit at yahoo.com (Alex Martelli) writes:
> greg <greg at cosc.canterbury.ac.nz> wrote:
> ...
> > Python does not currently provide any '__xxx__' special methods
> > corresponding to the 'and', 'or' and 'not' boolean operators. In the
> ...
> > There is no such difficulty in the case of 'not', however, and it
>
> Indeed, that's what the strangely-named __nonzero__ special method does:
> it's invoked upon the 'not' operator and in no other case,
Erm. No.
>>> class C(object):
... def __nonzero__(self):
... print 'hi!'
... return 1
...
>>> if C(): pass
...
hi!
Or do I misunderstand what you're saying?
Cheers,
mwh
--
Arrrrgh, the braindamage! It's not unlike the massively
non-brilliant decision to use the period in abbreviations
as well as a sentence terminator. Had these people no
imagination at _all_? -- Erik Naggum, comp.lang.lisp
More information about the Python-list
mailing list