python 在函数内部获取该函数名称

code

macname@localhost Desktop % cat exce.py    
import sys

def tmp_func():
    print(sys._getframe().f_code.co_name)

tmp_func()
macname@localhost Desktop % python3 exce.py
tmp_func
macname@localhost Desktop % 

原文地址:https://www.cnblogs.com/sea-stream/p/14049851.html