Copy constructors

Steve Holden sholden at
Fri Aug 10 02:03:37 CEST 2001

"Alex Martelli" <aleaxit at> wrote in message
news:9kuqsq02ts0 at
> "David Smith" <drs at> wrote in message
> news:3B72DCBA.C99465BC at
>     ...
> > class I have at hand, __init__ does some real work, which I want to
> > bypass -- I want to clone the results of that work.  I don't want to
>     ...
> > Is there a way for __copy__ to create a bare object of the same class,
> > which it can proceed to populate?
> Piece of cake:
> class Fleep:
>     def __init__(self, x, y, z):
>         print 'lots',x,'of',y,'work',z
>     def __copy__(self):
>         class Temp: pass
>         newbie = Temp()
>         newbie.__class__=self.__class__
>         print "very little work"

Surely I'm missing something here, but if (as I surmise) __copy__() is a
factory, shouldn't it let someone have newbie before it gets garbage

very-little-work-should-maybe-instead-return-newbie-ly y'rs  - steve

More information about the Python-list mailing list