How to get value of arguments passed to functions on the stack?

后端 未结 2 1072
暗喜
暗喜 2021-01-11 09:37

Using:

traceback.print_stack()

I can get:

  File \"x.py\", line 20, in 
    y(x)
  File \"x.py\", line 11, in         


        
2条回答
  •  长情又很酷
    2021-01-11 10:17

    You can probably rig something up by using inspect.getargvalues() and accessing the stack frame belonging to your traceback:

     inspect.getargvalues(traceback.tb_frame)
    

    You'll have to do some work to get the output exactly as desired. The above line is only for the innermost frame, so you'll have to walk up the stack and access the information you need for every frame. inspect.getouterframes() might come in handy.

提交回复
热议问题