ast.literal_eval ( ). " node Python: , , , , dicts, booleans None"., 20<30 , bool.
, literal_eval , eval, ..
import ast
expr = "20 < 30"
operator = "<"
lhs,rhs = map(ast.literal_eval, map(str.strip, expr.split(operator)))
eval("%s %s %s"%(lhs,operator,rhs))
Wrapping things in a sentence try, exceptwill lead to input errors in the evaluation lhs,rhs.
source
share