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内容请搜索靠谱客的其他文章。
发表评论 取消回复