Python装饰器和继承

Python装饰器和继承,第1张

Python装饰器和继承

定义

decor
静态方法并使用以下形式
@bar.decor

class bar(object):    def __init__(self):        self.val = 4    def setVal(self,x):        self.val = x    @staticmethod    def decor(func):        def increment(self, x): return func(self, x) + self.val        return incrementclass foo(bar):    def __init__(self):        bar.__init__(self)    @bar.decor    def add(self, x):        return x


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5629812.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存