python获得类名和函数名的方法

#!/usr/bin/python3
import sys

class Point:
   def __init__( self, x=0, y=0):
      self.x = x
      self.y = y
   def __del__(self):
      class_name = self.__class__.__name__
      fun_name = sys._getframe().f_code.co_name
      print (fun_name,class_name, "destroyed")

 

p = Point()
del p
__del__ Point destroyed

  

 

posted @ 2018-03-14 12:00  idvcn  阅读(271)  评论(0编辑  收藏  举报