我正在学习属性,并编写此代码只是为了了解它的工作原理:
class Car:
def __init__(self):
self.cities = 0
self.time = 0
self.efficiency = None
@property
def efficiency(self):
print('Calculating efficiency')
self.efficiency = self.cities / self.time
return self.efficiency
@efficiency.setter
def efficiency(self,input):
self.efficiency = input
当我尝试创建一个名为ejemplo
的对象(示例)时,出现RecursionError: maximum recursion depth exceeded while calling a Python object
错误。谁知道为什么?
这就是我创建ejemplo
:
ejemplo = Car()
print(ejemplo.cities)
print(ejemplo.time)
ejemplo.efficiency = 2
谢谢!