如何用Python获取当前执行的方法和类名?

2026-05-16 13:290阅读0评论SEO基础
  • 内容介绍
  • 相关推荐

本文共计87个文字,预计阅读时间需要1分钟。

如何用Python获取当前执行的方法和类名?

当然可以,请您提供需要改写的原文,我会帮您进行修改。

# 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()

  

如何用Python获取当前执行的方法和类名?