Copy constructors

Andrew Dalke dalke at
Fri Aug 10 09:35:00 CEST 2001

Joal Heagney wrote:
>And adding onto that an automatic copy of the instance's __dict__ -->

>... def __copy__(self):
>... class Temp: pass
>... newbie = Temp()
>... newbie.__class__ = self.__class__
>... newbie.__dict__ = copy.deepcopy(self.__dict__)
>... print "very little work"
>... return newbie


  def __copy__(self):
      return loads(dumps(self))

(but this assumes the created string is small enough to be

                    dalke at

More information about the Python-list mailing list