, :
class Foo(object):
def __init__(self, **inputs):
inputs['a'] = inputs.get('a', 1)
inputs['b'] = inputs.get('b', 2)
self.bar(**inputs)
def bar(self, *args, **kwargs):
print("bar got: %s" % kwargs)
Foo()
Foo(a=3, b=4)
, , , , , , <dict>.get().
__init__ :
def __init__(self, **inputs):
if 'a' not in inputs: inputs['a'] = 1
if 'b' not in inputs: inputs['b'] = 2
self.bar(**inputs)
def __init__(self, **inputs):
args = {'a': 1, 'b':2}
args.update(inputs)
self.bar(**args)
.