Class with too many parameters: better design strategy?

后端 未结 13 958
醉酒成梦
醉酒成梦 2020-12-04 08:29

I am working with models of neurons. One class I am designing is a cell class which is a topological description of a neuron (several compartments connected together). It ha

13条回答
  •  一个人的身影
    2020-12-04 08:59

    This is similar to the other solutions that iterate through a default dictionary, but it uses a more compact notation:

    class MyClass(object):
    
        def __init__(self, **kwargs):
            self.__dict__.update(dict(
                arg1=123,
                arg2=345,
                arg3=678,
            ), **kwargs)
    

提交回复
热议问题