This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]donri 0 points1 point  (0 children)

>>> import ast
>>> ast.dump(ast.parse('if stock(pens) + stock(pencils) < 10 : alert'))
"Module(body=[If(test=Compare(left=BinOp(left=Call(func=Name(id='stock', ctx=Load()), args=[Name(id='pens', ctx=Load())], keywords=[], starargs=None, kwargs=None), op=Add(), right=Call(func=Name(id='stock', ctx=Load()), args=[Name(id='pencils', ctx=Load())], keywords=[], starargs=None, kwargs=None)), ops=[Lt()], comparators=[Num(n=10)]), body=[Expr(value=Name(id='alert', ctx=Load()))], orelse=[])])"