zoukankan      html  css  js  c++  java
  • Python Frame objects 和Traceback objects

    Frame objects

    Frame objects represent execution frames. They may occur in traceback objects (see below).

    Special read-only attributes: f_back is to the previous stack frame (towards the caller), or None if this is the bottom stack frame; f_code is the code object being executed in this frame; f_locals is the dictionary used to look up local variables; f_globals is used for global variables; f_builtins is used for built-in (intrinsic) names; f_restricted is a flag indicating whether the function is executing in restricted execution mode; f_lasti gives the precise instruction (this is an index into the bytecode string of the code object).

    Special writable attributes: f_trace, if not None, is a function called at the start of each source code line (this is used by the debugger); f_exc_type, f_exc_value, f_exc_traceback represent the last exception raised in the parent frame provided another exception was ever raised in the current frame (in all other cases they are None); f_lineno is the current line number of the frame — writing to this from within a trace function jumps to the given line (only for the bottom-most frame). A debugger can implement a Jump command (aka Set Next Statement) by writing to f_lineno.

    Traceback objects

    Traceback objects represent a stack trace of an exception. A traceback object is created when an exception occurs. When the search for an exception handler unwinds the execution stack, at each unwound level a traceback object is inserted in front of the current traceback. When an exception handler is entered, the stack trace is made available to the program. (See section The try statement.) It is accessible as sys.exc_traceback, and also as the third item of the tuple returned by sys.exc_info(). The latter is the preferred interface, since it works correctly when the program is using multiple threads. When the program contains no suitable handler, the stack trace is written (nicely formatted) to the standard error stream; if the interpreter is interactive, it is also made available to the user as sys.last_traceback.

    Special read-only attributes: tb_next is the next level in the stack trace (towards the frame where the exception occurred), or None if there is no next level; tb_frame points to the execution frame of the current level; tb_lineno gives the line number where the exception occurred; tb_lasti indicates the precise instruction. The line number and last instruction in the traceback may differ from the line number of its frame object if the exception occurred in a try statement with no matching except clause or with a finally clause.

  • 相关阅读:
    开源项目之小玩具---各种机器人开源硬件
    目标检测之显著区域检测---国外的一个图像显著区域检测代码及其效果图 saliency region detection
    目标检测之指尖检测---指尖检测的新方法几种
    模式匹配之sift--- sift图像特征提取与匹配算法代码
    vi 之行号操作---显示行号、跳到指定行
    模式匹配之图像融合---小波变换的融合
    目标检测之harr---角点检测harr 的opencv实现
    java写 excel
    矩阵连乘最小权值
    leetcode Word Break I II 算法分析
  • 原文地址:https://www.cnblogs.com/tuzkee/p/2916772.html
Copyright © 2011-2022 走看看