konsodi.py 文件源码

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

项目:konsodi 作者: kharts 项目源码 文件源码
def get_result(self, code):
        """
        Get result of execution of the line of code
        :param code: string of code
        :type code: str
        :return: str
        """

        try:
            tree = ast.parse(code)
        except Exception, e:
            return str(e)
        if not tree.body:
            return ""
        if isinstance(tree.body[0], Expr):
            try:
                result = eval(code, self.globals)
            except Exception, e:
                return str(e)
            return str(result)
        else:
            try:
                exec code in self.globals
            except Exception, e:
                return str(e)
            return ""
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号