📅  最后修改于: 2022-03-11 14:57:47.238000             🧑  作者: Mango
>>> from attr import attrs, attrib, Factory
>>> @attrs
... class SomeClass(object):
... a_number = attrib(default=42)
... list_of_numbers = attrib(default=Factory(list))
...
... def hard_math(self, another_number):
... return self.a_number + sum(self.list_of_numbers) * another_number
>>> SomeClass(1, [1, 2, 3])
SomeClass(a_number=1, list_of_numbers=[1, 2, 3])