http://blog.csdn.net/callinglove/article/details/45483097
讲了一大堆,
我也是用来理解类继承当中的参数行为的。
=================
在任何时候继承类和重写方法的,我们应当用到’*args’和’**kwargs’将接收到的位置参数和键值参数给父类方法。
=================
测试代码
#!/usr/bin/env python# -*- coding: utf-8 -*-class Model(object): def __init__(self, name): self.name = name def save(self, force_update=False, force_insert=False): if force_update and force_insert: raise ValueError("Cannot perform both operations") if force_update: print "Updated an existing record" if force_insert: print "Created a new record"class ChildModel(Model): def save(self, *args, **kwargs): if self.name == 'abcd': super(ChildModel, self).save(*args, **kwargs) else: return Nonec = ChildModel('abcd')c.save(force_insert=True)c.save(force_update=True)
结果