Python 获取当前函数的函数名
sys._getframe().f_code.co_name
# -*- coding:utf-8 -*-
import sys
class test_class():
def hello(self):
print(sys._getframe().f_code.co_name)
def hello_world():
print('hello_world!')
print(sys._getframe().f_code.co_name)
if __name__ == '__main__':
ttt = test_class()
ttt.hello()
hello_world()
输出:
hello
hello_world!
hello_world
Process finished with exit code 0
转载自https://blog.csdn.net/lvhdbb/article/details/97923196

浙公网安备 33010602011771号