import inspect import sys def demo1(): f_name = inspect.getframeinfo(inspect.currentframe().f_back)[3][0] print(f_name) def demo2(): f_name = sys._getframe().f_code.co_name print(f_name) def demo3(): print(demo3.__name__) if __name__ == '__main__': demo1() demo2() demo3()
结果
demo1() demo2 demo3
标签:__,name,demo3,inspect,demo2,获取,print,执行,方法 From: https://www.cnblogs.com/daizichuan/p/17488752.html