sys._getframe()

2020-04-20  本文已影响0人  huashen_9126

1、获取调用者的函数名,两种方法

sys._getframe().f_back.f_code.co_name
# 或
sys._getframe(1).f_code.co_name

2、获取调用者的传参

import sys

def test(a):
    input_params = sys._getframe().f_locals.get('a')
    print(input_params )

def xx(a):
    test(a)

xx('aaaaa')

输出:aaaaa


参考资料:
https://blog.csdn.net/idwtwt/article/details/53542351
https://www.cnblogs.com/LegendOfBFS/p/3500227.html

上一篇 下一篇

猜你喜欢

热点阅读