python 獲取當前運行的 class 和 方法的名字


 

 

原文出處: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##

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM