2
class Test(object):
def __init__(self, a):
self.a = a
def __getattr__(self, name):
return getattr(self.a, name)
from pickle import loads, dumps
loads(dumps((Test(something),)))
我:Python pickle通過getattr獲得了acycle遞歸?
7 def __getattr__(self, name):
----> 8 return getattr(self.a, name)
RuntimeError: maximum recursion depth exceeded
任何暗示?
我可以通過改變像代碼解決這個問題:
if 'a' in self.__dict__:
return getattr(self.a, name)
,但我不想。有更好的解決方案
謝謝