I tried overriding __and__, but that is for the & operator, not and - the one that I want. Can I override and?
views:
315answers:
3
+1
A:
Not really. There's no special method name for the short-circuit logic operators.
S.Lott
2009-01-23 01:41:49
+4
A:
You cannot override the and, or, and not boolean operators.
Ignacio Vazquez-Abrams
2009-01-23 01:42:34
+12
A:
No you can't override and and or. With the behavior that these have in Python (i.e. short-circuiting) they are more like control flow tools than operators and overriding them would be more like overriding if than + or -.
You can influence the truth value of your objects (i.e. whether they evaluate as true or false) by overriding __nonzero__.
dF
2009-01-23 01:44:25