python inspect.stack() 的简单使用
1.
#python # -*- encoding: utf-8 -*- #獲取函數的名字 import inspect def debug():callnamer = inspect.stack()print('[debug] enter: {}'.format(callnamer))debug()[debug] enter: [FrameInfo(frame=<frame object at 0x000000000096D448>, filename='E:/pythontest/sort.py', lineno=6, function='debug', code_context=[' callnamer = inspect.stack()\n'], index=0), FrameInfo(frame=<frame object at 0x00000000008F8828>, filename='E:/pythontest/sort.py', lineno=9, function='<module>', code_context=['debug()\n'], index=0)]
可以看出是一個列表
2.選取列表的第二項
#python # -*- encoding: utf-8 -*- #獲取函數的名字 import inspect def debug():callnamer = inspect.stack()[1]print('[debug] enter: {}'.format(callnamer))debug()[debug] enter: FrameInfo(frame=<frame object at 0x00000000004A8828>, filename='E:/pythontest/sort.py', lineno=9, function='<module>', code_context=['debug()\n'], index=0)
3.選取函數的名字
#python # -*- encoding: utf-8 -*- #獲取函數的名字 import inspect def debug():callnamer = inspect.stack()[1][4]print('[debug] enter: {}'.format(callnamer))debug()[debug] enter: ['debug()\n']
轉載于:https://www.cnblogs.com/hixiaowei/p/10549731.html
總結
以上是生活随笔為你收集整理的python inspect.stack() 的简单使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Centos7防火墙的常用指令
- 下一篇: AS3 --调用Js