[英]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. 我正在寻找一种将** kwargs发送到具有已定义参数的函数的方法 ,而无需对其进行修改。
For example , I want to pass the parameters as **kwargs when calling the following init method: 例如 ,我想在调用以下init方法时将参数传递为** kwargs:
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? 有人可以考虑这样做吗?
ExampleClass(**{"attr1":1, "attr2":2, "attr3":3})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.