【发布时间】:2013-09-24 10:52:42
【问题描述】:
如何在 Python 中使用继承的装饰器?
class Foo:
@staticmethod
def keyErrorOnRed(f, colour):
if colour == "red":
raise KeyError("Better dead than red")
return lambda: f(*args, **kwargs)
class Bar(Foo):
@keyErrorOnRed("red")
def __init__(self, a, b):
self.vars = a, b
if __name__ == '__main__':
barObj = Bar('can', 'haz')
【问题讨论】:
标签: python inheritance static-methods instantiation python-decorators