获取所有参数,并作为变量保存
class Person(object):
def __init__(self, name, gender, **kw):
for k, v in kw.iteritems():
setattr(self, k, v)
p = Person(‘Bob‘, ‘Male‘, age=18, course=‘Python‘)
print p.age
print p.course
原文:http://blog.csdn.net/qianguozheng/article/details/44653133