python获取当前运行函数名

 

两种方式:

#!/usr/bin/env python3
#coding:utf-8

import sys, inspect
def test_a():
print('func name: ', sys._getframe().f_code.co_name)

def test_b():
print('func name: ', inspect.stack()[0][3])

test_a()
test_b()

 

https://wenku.baidu.com/view/ae74f4e60f22590102020740be1e650e52eacfc8.html

posted @ 2022-10-25 23:20  i舒  阅读(37)  评论(0编辑  收藏  举报