类中定义装饰器 装饰类中的实例方法
作者:互联网
# def decorate(func):
# def inner(self,value):
# func(self,value)
# print(self.v)
#
# return inner
class Computer():
def __init__(self, value):
self.v = value
def decorate(func, ):
def inner(self, value):
func(self, value)
print(self.v)
return inner
@decorate
def add(self, value):
self.v += value
@decorate
def low(self, value):
self.v -= value
@decorate
def multi(self, value):
self.v *= value
c = Computer(2)
c.add(3)
标签:self,value,实例,类中,func,inner,装饰,def,decorate 来源: https://blog.csdn.net/zhouxuan612/article/details/120216501