[Baypiggies] overriding boolean and,or operators?
slacy at slacy.com
Mon Jul 12 20:21:29 CEST 2010
According to http://docs.python.org/library/operator.html boolean operators
==, <, >, etc. can be overridden via __eq__(), __lt__(), __gt__(), etc.
They also mention *bitwise* and/or operators via __and__() and __or__().
But, I'd like to override the *boolean* operators 'and' and 'or'. Is this
I'm experimenting with a library that takes a python expression like this:
"(a == b) or (c and d)"
And instead of evaluating it via the interpreter, creates (and returns) a
representation of said boolean decision tree such that it can be evaluated
dynamically and/or converted to some other form, like prefix or postfix
(this is just an example and for my own exploration and deeper understanding
of operator overrides).
I can get this to work if I use the syntax "(a == b) | (c & d)" but I would
prefer to use the more pythonic and syntactically correct "and" and "or".
Is this possible?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Baypiggies