def autoInitClass(OldClass):
superClass = OldClass.mro()[1]
class NewClass(OldClass):
def __init__(*args):
self = args[0]
superClass.__init__(self)
apply(OldClass.__init__, args)
return NewClass
使用autoInitClass装饰器构造新类:
代码如下:
@autoInitClass
class T2(threading.Thread):
def __init__(self, a, b, c):
#不用再写super(T2, self).__init__()
self.a = a
self.b = b
self.c = c
def run(self):
print self.a, self.b, self.c
本文来自: itianda's blog ,转载请注明原文出处