Alternative to eval in Python

前端 未结 2 1771
有刺的猬
有刺的猬 2021-01-13 12:21

Python eval is quite slow. I need to evaluate simple boolean expression with logical operators (like \"True or False\"). I am doing this for thousands of line o

2条回答
  •  忘掉有多难
    2021-01-13 12:56

    import operator
    ops = { 'or': operator.or_, 'and': operator.and_ }
    print ops[op](True, False)
    

提交回复
热议问题