我一直在使用這種複製方法很長一段時間,在很多需要它的類中。Python:copy.deepcopy產生錯誤
class population (list):
def __init__ (self):
pass
def copy(self):
return copy.deepcopy(self)
它突然開始生產這個錯誤:
File "C:\Python26\lib\copy.py", line 338, in _reconstruct
state = deepcopy(state, memo)
File "C:\Python26\lib\copy.py", line 162, in deepcopy
y = copier(x, memo)
File "C:\Python26\lib\copy.py", line 255, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Python26\lib\copy.py", line 189, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "C:\Python26\lib\copy.py", line 323, in _reconstruct
y = callable(*args)
File "C:\Python26\lib\copy_reg.py", line 93, in __newobj__
return cls.__new__(cls, *args)
TypeError: object.__new__(generator) is not safe, use generator.__new__()
>>>
,其中包括到線338,162,255的參考線,189是在「338行」之前重複好幾次說我在這裏複製。
我是新來的,我剛剛嘗試過使用'yield'。所以我最好更多地閱讀它們。是的,當我刪除'yield'時,錯誤消失了。謝謝 – 2009-09-09 19:52:01
似乎鏈接已死亡。 – antonagestam 2013-08-28 11:12:39
@antonagestam固定。 – wRAR 2013-08-28 16:37:36