我是靠谱客的博主 魁梧书包,最近开发中收集的这篇文章主要介绍traceback.print_stack(file=sys.stdout)与traceback.extract_stack(),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

import sys
import traceback
def show():
    #traceback.print_stack(file=sys.stdout)

    s =  traceback.extract_stack()
    print '%s Invoked me!'%s[-2][2]
    print "hello world"

 

def get_cur_info():
   
    show()

if __name__ == '__main__':
    get_cur_info()

 

> ./mypthon
get_cur_info Invoked me!
hello world

#######################################

import sys
import traceback
def show():
    #traceback.print_stack(file=sys.stdout)

    s =  traceback.extract_stack()
    print '%s Invoked me!'%s[-3][2]
    print "hello world"

 

def get_cur_info():
   
    show()

if __name__ == '__main__':
    get_cur_info()

 

>./mypthon
<module> Invoked me!
hello world

 

#######################################

import sys
import traceback
def show():
    traceback.print_stack(file=sys.stdout)

    s =  traceback.extract_stack()
    print '%s Invoked me!'%s[-3][2]
    print "hello world"

 

def get_cur_info():
   
    show()

if __name__ == '__main__':
    get_cur_info()

> ./mypthon
  File "./mypthon", line 70, in <module>
    get_cur_info()
  File "./mypthon", line 58, in get_cur_info
    show()
  File "./mypthon", line 45, in show
    traceback.print_stack(file=sys.stdout)
get_cur_info Invoked me!
hello world

 

最后

以上就是魁梧书包为你收集整理的traceback.print_stack(file=sys.stdout)与traceback.extract_stack()的全部内容,希望文章能够帮你解决traceback.print_stack(file=sys.stdout)与traceback.extract_stack()所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部