返回::[wiki:self/PyIAQ Python 罕见问题集]
::-- ZoomQuiet [DateTime(2005-09-06T04:10:30Z)] TableOfContents
1. 问:创建对象很爽,但是如何更新?
Q: That's great for creating objects; How about for updating? Well, dictionaries have an update method, so you could do d.update(Dict(a=100, b=200)) when d is a dictionary. There is no corresponding method for objects, so you have to do obj.a = 100; obj.b = 200. Or you could define one function to let you do update(x, a=100, b=200) when x is either a dictionary or an object:
This is especially nice for constructors: