📜  如何使用 kwargs python 代码示例设置类属性

📅  最后修改于: 2022-03-11 14:46:11.247000             🧑  作者: Mango

代码示例1
# In parent Class
def __init__(self, attributes):
    for key, value in attributes.items():
        self.__dict__[key] = value
# In child Class
def __init__(self, **kwargs):
    attributes = {k:v for k,v in kwargs.items() if v}
    super().__init__(attributes)