Thursday, 12 February 2015

list.copy() how much does it copy?

So for my previous post, I mentioned that the list gets copied, so having multiple parents is not possible. But, what does list.copy() actually copy?
I initially thought that it copies everything and I originally thought that copy was a call existent in the object class equivalent to eval(repr(obj)). But according to the following... I was wrong:

In fact, when you try to call copy on user implemented object (I tried it on tree) that does not define copy themselves, you get an error.

Anyhow, this means I was wrong about my previous conclusion and to actually duplicate the Tree objects, you actually need to use "deep copy". I think the easiest way to implement this would be to use eval(repr(Obj)).

No comments:

Post a Comment