Search code examples
pythonpython-3.xkeyword-argument

How to send **kwargs to a function with defined parameters?


I'm looking for a way to send **kwargs to a function with defined parameters, without having to modify it.

For example, I want to pass the parameters as **kwargs when calling the following init method:

class ExampleClass(object):
def __init__(self, attr1=None, attr2=None, attr3=None):
    super(ExampleClass, self).__init__()
    self.attr1=attr1
    self.attr2=attr2
    self.attr3=attr3

Can anyone think of a way doing so?


Solution

  • ExampleClass(**{"attr1":1, "attr2":2, "attr3":3})