Override 'and' and 'or'

Wildemar Wildenburger lasses_weil at klapptsowieso.net
Sun Oct 7 10:21:54 EDT 2007


Dekker wrote:
> Is it possible to override 'and' and/or 'or'? I cannot find a special
> method for it... __and__ and __rand__ and __or__ and __ror__ are for
> binary manipulation... any proposals?
> 
> Have marvelous sunday,
> Marco
> 
I guess you're looking for __nonzero__() 
<URL:http://docs.python.org/ref/customization.html>.

You don't actually override the boolean operators, you just tell the 
object how to tell others if it evaluates to True or False 
(Truth-testing isn't a binary operation; cf. bool(my_object)).

/W



More information about the Python-list mailing list