当前位置: 首页>>代码示例>>Python>>正文


Python traceback.FrameSummary方法代码示例

本文整理汇总了Python中traceback.FrameSummary方法的典型用法代码示例。如果您正苦于以下问题:Python traceback.FrameSummary方法的具体用法?Python traceback.FrameSummary怎么用?Python traceback.FrameSummary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在traceback的用法示例。


在下文中一共展示了traceback.FrameSummary方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_exception

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def format_exception(
    exp: BaseException, tb: Optional[List[traceback.FrameSummary]] = None
) -> str:
    """Formats an exception traceback as a string, similar to the Python interpreter."""

    if tb is None:
        tb = traceback.extract_tb(exp.__traceback__)

    # Replace absolute paths with relative paths
    cwd = os.getcwd()
    for frame in tb:
        if cwd in frame.filename:
            frame.filename = os.path.relpath(frame.filename)

    stack = "".join(traceback.format_list(tb))
    msg = str(exp)
    if msg:
        msg = ": " + msg

    return f"Traceback (most recent call last):\n{stack}{type(exp).__name__}{msg}" 
开发者ID:kdrag0n,项目名称:pyrobud,代码行数:22,代码来源:error.py

示例2: __init__

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def __init__(self, thread, calling_filename, calling_line_number, call_stack):
        self.thread = thread
        self.file_name = calling_filename
        self.line_number = calling_line_number
        self.call_stack: List[traceback.FrameSummary] = call_stack
        self.time = time.time() 
开发者ID:Bertrand256,项目名称:dash-masternode-tool,代码行数:8,代码来源:thread_utils.py

示例3: getTextFromFile

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def getTextFromFile(block_id: str, stack_pos: traceback.FrameSummary):
    """ get the text which corresponds to the block_id (e.g. which figure) at the given position sepcified by stack_pos. """
    block_id = lineToId(block_id)
    block = None

    if not stack_pos.filename.endswith('.py') and not stack_pos.filename.startswith("<ipython-input-"):
        raise RuntimeError("pylustrator must used in a python file (*.py) or a jupyter notebook; not a shell session.")

    with open(stack_pos.filename, 'r', encoding="utf-8") as fp1:
        for lineno, line in enumerate(fp1, start=1):
            # if we are currently reading a pylustrator block
            if block is not None:
                # add the line to the block
                block.add(line)
                # and see if we have found the end
                if line.strip().startswith("#% end:"):
                    block.end()
            # if there is a new pylustrator block
            elif line.strip().startswith("#% start:"):
                block = Block(line)

            # if we are currently reading a block, continue with the next line
            if block is not None and not block.finished:
                continue

            if block is not None and block.finished:
                if block.id == block_id:
                    return block
            block = None
    return [] 
开发者ID:rgerum,项目名称:pylustrator,代码行数:32,代码来源:change_tracker.py

示例4: test_basics

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def test_basics(self):
        linecache.clearcache()
        linecache.lazycache("f", globals())
        f = traceback.FrameSummary("f", 1, "dummy")
        self.assertEqual(f,
            ("f", 1, "dummy", '"""Test cases for traceback module"""'))
        self.assertEqual(tuple(f),
            ("f", 1, "dummy", '"""Test cases for traceback module"""'))
        self.assertEqual(f, traceback.FrameSummary("f", 1, "dummy"))
        self.assertEqual(f, tuple(f))
        # Since tuple.__eq__ doesn't support FrameSummary, the equality
        # operator fallbacks to FrameSummary.__eq__.
        self.assertEqual(tuple(f), f)
        self.assertIsNone(f.locals) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_traceback.py

示例5: test_lazy_lines

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def test_lazy_lines(self):
        linecache.clearcache()
        f = traceback.FrameSummary("f", 1, "dummy", lookup_line=False)
        self.assertEqual(None, f._line)
        linecache.lazycache("f", globals())
        self.assertEqual(
            '"""Test cases for traceback module"""',
            f.line) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_traceback.py

示例6: test_explicit_line

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import FrameSummary [as 别名]
def test_explicit_line(self):
        f = traceback.FrameSummary("f", 1, "dummy", line="line")
        self.assertEqual("line", f.line) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_traceback.py


注:本文中的traceback.FrameSummary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。