通过添加一些额外的参数,我是否可以在Python中使用任何魔术来有效地使用超级构造函数?
理想情况下,我想使用以下方法:
class ZipArchive(zipfile.ZipFile):
def __init__(self, verbose=True, **kwargs):
"""
Constructor with some extra params.
For other params see: zipfile.ZipFile
"""
self.verbose = verbose
super(ZipArchive, self).__init__(**kwargs)
然后能够使用原始的构造函数参数以及我的类中的一些其他内容。像这样:
zip = ZipArchive('test.zip', 'w')
zip = ZipArchive('test.zip', 'w', verbose=False)
我正在使用Python 2.6,但是如果只有在更高版本的Python中才能实现魔力,那么我也很感兴趣。
编辑:我可能应该提到上面的方法不起作用。错误是:TypeError: __init__() takes at most 2 arguments (3 given)
相关分类