4 ms·
I don't see much value autoassignining args. I do see being useful at times to auto-assign kwargs. class Base(object): def __init__(self, *args, **kws)
by galois17 13y ago
I don't see much value autoassignining args. I do see being useful at times to auto-assign kwargs.
class Base(object):
def __init__(self, *args, **kws):
self.__dict__.update(kws)
class Foo(Base):
def__init__("foo", age=30):
self.name = "foo"
super(Foo, self).__init__("foo", age=30)
or you can do the same using a decorator for the init.
def update(init_meth):
def wrapped(self, *args, **kws):
init_meth(self, *args, **kws)
self.__dict__.update(kws)
return wrapped
class Foo(object):
@update
def__init__("foo", age=30):
self.name = "foo"