Dynamically evaluating simple boolean logic in Python

后端 未结 5 480
一向
一向 2020-12-08 22:40

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 t
5条回答
  •  春和景丽
    2020-12-08 23:08

    If you set up dicts with the locals and globals you care about then you should be able to safely pass them along with the expression into eval().

提交回复
热议问题