Proto-PEP: Overloadable Boolean Operators
aleaxit at yahoo.com
Mon Sep 6 15:21:12 CEST 2004
Michael Hudson <mwh at python.net> wrote:
> 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
> Or do I misunderstand what you're saying?
Oops, no, you're right, I was wrong -- not sure why I had that
misconception in my mind right now...
More information about the Python-list