當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。