tags:

views:

96

answers:

1

I have been using this copy method for quite a while, in lots of classes that needed it.

class population (list):
def __init__ (self):
    pass

def copy(self):
    return copy.deepcopy(self)

It has suddenly started producing this error:

     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__()
>>>

the lines which include the references to lines 338, 162, 255, 189 were repeated quite a few times before the 'line 338' that I copied here.

+3  A: 

Are you cloning a generator? Generators can't be cloned.

wRAR
I'm new at this, and I had just tried to use a 'yield' . So I'd better read up more on them. Yes, when I removed the 'yield' the error went away. Thanks
Peter Stewart