Asked • 04/12/19

Dynamically evaluating simple boolean logic in Python?

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, 1. Convert this information to a Python expression like `True or (True or False)` and `eval` it? 1. Create a binary tree where a node is either a `bool` or `Conjunction`/`Disjunction` object and recursively evaluate it? 1. Convert it into nested S-expressions and use a Lisp parser? 4. Something else? Suggestions welcome.

Matthew B.

Can you post the full code?
Report

11/12/19

1 Expert Answer

By:

Max B. answered • 04/06/23

Tutor
0 (0)

University lecturer & senior engineer tutoring Python, other languages

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.