Python 类上的最大递归深度
我有一个类,我正试图将它设置为True,比如:Python 类上的最大递归深度,python,class,python-3.x,Python,Class,Python 3.x,我有一个类,我正试图将它设置为True,比如: file = FileProperties(long, lat, timestamp, compas, filename) [...] file.is_duplicate = True 我得到了一个运行时错误:调用Python对象时超过了最大递归深度我到底做错了什么?文件类的创建也发生在for循环中,但我认为这不是这个特定错误的问题 class FileProperties(object): def __init__(self, long
file = FileProperties(long, lat, timestamp, compas, filename)
[...]
file.is_duplicate = True
我得到了一个运行时错误:调用Python对象时超过了最大递归深度我到底做错了什么?文件类的创建也发生在for循环中,但我认为这不是这个特定错误的问题
class FileProperties(object):
def __init__(self, longitude, latitude, timestamp, compas, filename):
self._longitude = longitude
self._latitude = latitude
self._timestamp = timestamp
self._filename = filename
self._compas = compas
self._duplicate = False
self._teleporting = False
@property
def get_lat(self):
return self._latitude
@property
def get_long(self):
return self._longitude
@property
def get_timestamp(self):
return self._timestamp
@property
def get_filename(self):
return self._filename
@property
def get_compas(self):
return self._compas
@property
def is_duplicate(self):
return self._duplicate
@property
def is_teleporting(self):
return self._teleporting
@is_duplicate.setter
def is_duplicate(self, value):
self.is_duplicate = value
@is_teleporting.setter
def is_teleporting(self, value):
self._teleporting = value
在:
将self.is_duplicate更改为self._duplicate,我想应该可以工作(否则请提供一个最小的工作示例)
出现此错误的原因是,您分配的方法是_duplicate而不是属性_duplicate,因此您创建了一个无限调用循环,因为该方法试图在无限循环中设置自己,因为它一次又一次地通过setter 您应该质疑为什么要对这些简单属性使用getter。因为我将对它们进行验证,但我想简化脚本,以方便出现帮助输入错误,请不要感到羞耻,但请尝试一下,并报告这是否解决了您的问题,这可能对其他人有帮助。我还要再等4分钟才能接受你的邀请answer@James啊,我不知道有最低时限!谢谢你接受我的回答:)
@is_duplicate.setter
def is_duplicate(self, value):
self.is_duplicate = value