class Lazyproperty:
def __init__(self,func):
self.func=func
def __get__(self, instance, owner):
if instance:
res=self.func(instance)
setattr(instance,self.func.__name__,res)
# instance.__dict__[self.func.__name__]=res
return res
return self
class myclassmethod:
def __init__(self,func):
self.__func=func
def __get__(self, instance, owner):
def feedback(*args,**kwargs):
return self.__func(owner,*args,**kwargs)
return feedback
class mystaticmethod:
def __init__(self,func):
self.__func=func
def __get__(self, instance, owner):
def feedback(*args,**kwargs):
return self.__func(*args,**kwargs)
return feedback
class Room:
def __init__(self,name,width,length):
self.name=name
self.width=width
self.length=length
@Lazyproperty #area=Lazyproperty(area) 相当于'定义了一个类属性,即描述符'
def area(self):
return self.width * self.length
#
# @classmethod
@myclassmethod #myclsmethod=myclassmethod(myclsmethod)
def myclsmethod(self,msg):
print(msg)
# @staticmethod
@mystaticmethod
def mystatic(self):
return 13