Linux 拨号vps windows公众号手机端

python如何获取函数名

lewis 6年前 (2019-03-29) 阅读数 10 #程序编程
文章标签 python

在python中获取函数名的方法

1.在类内部获取函数名

import sys

class testsqawd(object):

def hello(self):

print('the name of method is ## {}##'.format(sys._getframe().f_code.co_name))

print('the name of class is ## {} ##'.format(self.__class__.__name__))

if __name__ == '__main__':

ttt = testsqawd()

ttt.hello()

2.在函数内部获取函数名

def my_name():

print(sys._getframe().f_code.co_name)

print(inspect.stack()[0][3])

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门