我用self.k = v 代替setattr(self, k,v),为什么不行?
代码如下:
class Person(object):
def __init__(self,name,gender,birth,**args):
self.name = name
self.gender = gender
self.birth = birth
for k,v in args.iteritems():
print k,":",v
self.k = v
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='student')
print xiaoming.name
print xiaoming.job