Python 3.x Python:RecursionError:删除时超过最大递归深度
我已经为我的类定义了一个属性,稍后在析构函数中删除该属性。但在那一刻,我犯了一个错误 这是我的班级:Python 3.x Python:RecursionError:删除时超过最大递归深度,python-3.x,Python 3.x,我已经为我的类定义了一个属性,稍后在析构函数中删除该属性。但在那一刻,我犯了一个错误 这是我的班级: class PBPPlayers: def __init__(self, id_game_feb): self.__id_game_feb = id_game_feb def __del__(self): del self.__id_game_feb '''Properties''' @property def __i
class PBPPlayers:
def __init__(self, id_game_feb):
self.__id_game_feb = id_game_feb
def __del__(self):
del self.__id_game_feb
'''Properties'''
@property
def __id_game_feb(self):
return self.__id_game_feb
@__id_game_feb.setter
def __id_game_feb(self, value):
self.__id_game_feb = value
@__id_game_feb.deleter
def __id_game_feb(self):
del self.__id_game_feb
这是您可以用来测试它的测试文件:
import unittest
import os
from parsers.feb.playbyplay.PBPPlayers import PBPPlayers
class MyTestCase(unittest.TestCase):
def setUp(self) -> None:
os.chdir(os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..')))
def test_json(self):
pbp_data_players = PBPPlayers(2171202)
if __name__ == '__main__':
unittest.main()
我得到的错误是:
Error
Traceback (most recent call last):
File "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
yield
File "/usr/lib/python3.6/unittest/case.py", line 605, in run
testMethod()
File "/home/josecarlos/Workspace/python/basketmetrics/test/test_feb_pbp_players.py", line 11, in test_json
pbp_data_players = PBPPlayers(2171202)
File "/home/josecarlos/Workspace/python/basketmetrics/parsers/feb/playbyplay/PBPPlayers.py", line 7, in __init__
self.__id_game_feb = id_game_feb
File "/home/josecarlos/Workspace/python/basketmetrics/parsers/feb/playbyplay/PBPPlayers.py", line 33, in __id_game_feb
self.__id_game_feb = value
File "/home/josecarlos/Workspace/python/basketmetrics/parsers/feb/playbyplay/PBPPlayers.py", line 33, in __id_game_feb
self.__id_game_feb = value
File "/home/josecarlos/Workspace/python/basketmetrics/parsers/feb/playbyplay/PBPPlayers.py", line 33, in __id_game_feb
self.__id_game_feb = value
[Previous line repeated 475 more times]
RecursionError: maximum recursion depth exceeded
Exception ignored in: <bound method PBPPlayers.__del__ of <parsers.feb.playbyplay.PBPPlayers.PBPPlayers object at 0x7f837b16f438>>
Traceback (most recent call last):
File "/home/josecarlos/Workspace/python/basketmetrics/parsers/feb/playbyplay/PBPPlayers.py", line 11, in __del__
del self.__id_game_feb
File "/home/josecarlos/Workspace/python/basketmetrics/parsers/feb/playbyplay/PBPPlayers.py", line 37, in __id_game_feb
del self.__id_game_feb
File "/home/josecarlos/Workspace/python/basketmetrics/parsers/feb/playbyplay/PBPPlayers.py", line 37, in __id_game_feb
del self.__id_game_feb
File "/home/josecarlos/Workspace/python/basketmetrics/parsers/feb/playbyplay/PBPPlayers.py", line 37, in __id_game_feb
del self.__id_game_feb
[Previous line repeated 476 more times]
RecursionError: maximum recursion depth exceeded
from com.parsers.json.json import JSon
from constants import URL
class PBPPlayers:
def __init__(self, id_game_feb):
self._id_game_feb = id_game_feb
def __del__(self):
del self._id_game_feb
'''Properties'''
@property
def _id_game_feb(self):
return self.__id_game_feb
@_id_game_feb.setter
def _id_game_feb(self, value):
self.__id_game_feb = value
@_id_game_feb.deleter
def _id_game_feb(self):
del self.__id_game_feb