当前位置 : 主页 > 编程语言 > python >

python 获取当前运行的 class 和 方法的名字

来源:互联网 收集:自由互联 发布时间:2022-09-02
# 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 = H
# 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()

  



网友评论