compact_tracebacks.py 文件源码

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

项目:goreviewpartner 作者: pnprog 项目源码 文件源码
def log_traceback_from_info(exception_type, value, tb, dst=sys.stderr, skip=0):
    """Log a given exception nicely to 'dst', showing a traceback.

    dst  -- writeable file-like object
    skip -- number of traceback entries to omit from the top of the list

    """
    for line in traceback.format_exception_only(exception_type, value):
        dst.write(line)
    if (not isinstance(exception_type, str) and
        issubclass(exception_type, SyntaxError)):
        return
    print >>dst, 'traceback (most recent call last):'
    text = None
    for filename, lineno, fnname, text in traceback.extract_tb(tb)[skip:]:
        if fnname == "?":
            fn_s = "<global scope>"
        else:
            fn_s = "(%s)" % fnname
        print >>dst, "  %s:%s %s" % (filename, lineno, fn_s)
    if text is not None:
        print >>dst, "failing line:"
        print >>dst, text
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号