Dynamically evaluating simple boolean logic in Python
Posted
by a paid nerd
on Stack Overflow
See other posts from Stack Overflow
or by a paid nerd
Published on 2010-03-18T04:49:55Z
Indexed on
2010/03/18
4:51 UTC
Read the original article
Hit count: 533
I've got some dynamically-generated boolean logic expressions, like:
- (A or B) and (C or D)
- A or (A and B)
- A
- empty - evaluates to True
The placeholders get replaced with booleans. Should I,
- Convert this information to a Python expression like
True or (True or False)
andeval
it? - Create a binary tree where a node is either a
bool
orConjunction
/Disjunction
object and recursively evaluate it? - Convert it into nested S-expressions and use a Lisp parser?
- Something else?
Suggestions welcome.
© Stack Overflow or respective owner