Eliran Shem Tov
Eliran Shem Tov

Reputation: 628

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?

Upvotes: 0

Views: 196

Answers (1)

lingxiao
lingxiao

Reputation: 1224

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

Upvotes: 2

Related Questions