expression.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:deb-python-lesscpy 作者: openstack 项目源码 文件源码
def operate(self, vala, valb, oper):
        """Perform operation
        args:
            vala (mixed): 1st value
            valb (mixed): 2nd value
            oper (str): operation
        returns:
            mixed
        """
        operation = {
            '+': operator.add,
            '-': operator.sub,
            '*': operator.mul,
            '/': operator.truediv,
            '=': operator.eq,
            '>': operator.gt,
            '<': operator.lt,
            '>=': operator.ge,
            '=<': operator.le,
        }.get(oper)
        if operation is None:
            raise SyntaxError("Unknown operation %s" % oper)
        ret = operation(vala, valb)
        if oper in '+-*/' and int(ret) == ret:
            ret = int(ret)
        return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号