簡體   English   中英

類上的最大遞歸深度

[英]Maximum recursion depth on class

我有一個類,我試圖將is_duplicate設置為True,如:

file = FileProperties(long, lat, timestamp, compas, filename)
[...]
file.is_duplicate = True

我得到一個RuntimeError:在調用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

在:

@is_duplicate.setter
def is_duplicate(self, value):
    self.is_duplicate = value

將self.is_duplicate更改為self._duplicate並且它應該可以正常工作(否則請提供最小的工作示例)。

這個錯誤的原因是你正在分配方法is_duplicate而不是屬性_duplicate,因此你創建了一個無限的調用循環,因為該方法試圖將自己設置為無限循環,因為它一次又一次地通過setter ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM