通过描述符和类装饰器,自定义staicmethod(静态方法)

class StaticMethod:
    def __init__(self,func):
        self.func = func

    def __get__(self, instance, owner):
        def deco(*args,**kwargs):
            return self.func(*args,**kwargs)
        return deco

class Room:
    @staticmethod
    def area(width,length,higt):
        return width * length * higt

    @StaticMethod
    def area1(width,length,higt):
        return width * length * higt

print(Room.area(10,20,1))
print(Room.area1(10,20,1))
r = Room()
print(r.area(10,20,2))
print(r.area1(10,20,2))

 

相关文章:

  • 2021-06-12
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2021-04-02
  • 2022-12-23
  • 2022-01-08
猜你喜欢
  • 2022-03-08
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2021-05-26
相关资源
相似解决方案