美文网首页
sys._getframe()

sys._getframe()

作者: huashen_9126 | 来源:发表于2020-04-20 23:25 被阅读0次

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

相关文章

网友评论

      本文标题:sys._getframe()

      本文链接:https://www.haomeiwen.com/subject/oydjihtx.html