1 Jan
2011
1 Jan
'11
6:57 a.m.
On Sun, Dec 19, 2010 at 9:44 PM, spir
I find those loads of "self.x=x" in constructors sooo stupid --I want the machine to do it for me. __init__ should only define the essential part of obj construction; while the final constructor would do some mechanical job in addition.
Automating that is quite easy with keyword arguments:
class Foo(object): ... def __init__(self, **kwargs): ... self.__dict__.update(kwargs) ... f = Foo(a=1, b=2) f.a 1 f.b 2
If you want to play safe, filter out keys that start with '__'. Best regards and a happy new year! Mart Sõmermaa