python 函数的获取当前栈信息
示例代码
import sys
def example_function():
frame = sys._getframe()
for attr_name in dir(frame):
if not attr_name.startswith('__'):
attr_value = getattr(frame, attr_name)
print('attr_name={attr_name}: attr_value={attr_value}'.format(attr_name=attr_name, attr_value=attr_value))
code_obj = frame.f_code
for attr_name in dir(code_obj):
if not attr_name.startswith('__'):
attr_value = getattr(code_obj, attr_name)
print('attr_name={attr_name}: attr_value={attr_value}'.format(attr_name=attr_name, attr_value=attr_value))
example_function()
关键代码
sys._getframe().f_code.co_name
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/18957231

浙公网安备 33010602011771号