我有一个具有很多属性的类,这些属性在instanciating(init)时提供。
看起来像这样,但还有大约30个attr:class SomeObject:
def __init__(self,
first,
second):
self.first = first
self.second = second
工作正常,但很长很重复,很难更新。
在我使用更小的课程之前:class SomeObject:
def __init__(self, **attr):
self.__dict__.update(attr)
工作得很好,更容易,但很难跟踪。当使用IDE(我使用PyCharm)时,我在编写对象时没有提示,自动完成提示通常不起作用。
我会寻找两个类的混合,如:class SomeObject:
def __init__(self,
first,
second):
self.__dict__.update(???) # I would like to do it in a single line, so I dont have to write a new attr two (three...) times.
有谁知道这是否可行?非常感谢
Python 3.4 + PyCharm 2016.1 CommunityEdition
...编辑/补充......
问题似乎主要是“保留”IDE中的代码检查,以便对象上仍然可以使用自动完成等。