原文出处:python 获取当前运行的 class 和 方法的名字

 

# coding=utf-8
 
import sys
class Hello():
 
    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__":
    h = Hello()
    h.hello()

运行结果:

the name of method is ## hello ##
the name of class is ##Hello##

 

相关文章:

  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
  • 2021-10-01
  • 2021-12-09
  • 2021-08-30
猜你喜欢
  • 2022-12-23
  • 2021-07-21
  • 2022-02-24
  • 2022-02-01
  • 2022-12-23
  • 2021-08-01
相关资源
相似解决方案