@property defdescription(self): """ Return a description of this car. """ return" ".join(str(getattr(self, attr, "Unknown")) for attr in self.__dict__)
在Python3中需要提供一个命名参数:
1 2 3 4 5
classCar(object, mateclass=AttributeInitType): @property defdescription(self): """ Return a description of this car. """ return" ".join(str(value) for value in self.__dict__.values())
classCar(object): def__init__(self, **kwargs): for name, value in kwargs.items(): setattr(self, name, value) @property defdescription(self): return" ".join(str(value) for value in self.__dict__.values())