[Tutor] question concerning deepcopy

Kent Johnson kent37 at tds.net
Sat Apr 29 12:49:59 CEST 2006

Gregor Lingl wrote:
> Thanks, Kent  for the hint. It works (of course).
> Skimming through this part of the docs I discovered, that there is a 
> special method __deepcopy__. So I also  tried using this, adding
> 	def __deepcopy__(self,visit):
> 		return self
> to my Vec class, which also seems to work. (I think this not to
> be harmful as Vecs should be, like tuples, immutable).
> And, indeed, it also seems to work.

That is not a correct deep copy, it is a shallow copy. Although Vec 
objects are immutable they may contain mutable objects. The point of 
deep copy is to copy "all the way down" so the objects contained by a 
Vec should also be copied.


More information about the Tutor mailing list