From 544a2b6e6273db5d5657576aef9dce71922b7b60 Mon Sep 17 00:00:00 2001 From: Sfan5 Date: Mon, 6 Jan 2014 16:27:57 +0100 Subject: [PATCH] [Calc] Allow sum() too --- calc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/calc.py b/calc.py index 1724832..9eeafeb 100755 --- a/calc.py +++ b/calc.py @@ -13,7 +13,7 @@ import math operators = {ast.Add: op.add, ast.Sub: op.sub, ast.Mult: op.mul, ast.Pow: op.pow, ast.Div: op.truediv, ast.BitXor: op.xor, ast.Mod: op.mod} -funcs = {"bin": bin, "abs": abs, "oct": oct, "int": int} +funcs = {"bin": bin, "abs": abs, "oct": oct, "int": int, "sum": sum} for funcn in dir(math): if funcn.startswith("__"): @@ -38,9 +38,9 @@ def eval_(node): return eval_(node.op)(eval_(node.left), eval_(node.right)) elif isinstance(node, ast.Call): # ( ) return getfunc(node.func.id)(*(eval_(e) for e in node.args)) - elif isinstance(node. ast.Tuple): # ( , , [...] ) + elif isinstance(node, ast.Tuple): # ( , , [...] ) return tuple(eval_(e) for e in node.elts) - elif isinstance(node. ast.List): # [ , , [...] ] + elif isinstance(node, ast.List): # [ , , [...] ] return list(eval_(e) for e in node.elts) else: raise TypeError("AST node type not allowed: '" + type(node).__name__ + "'")