Copy constructors

James_Althoff at James_Althoff at
Mon Aug 13 20:31:05 CEST 2001

and when using 2.2

        class Temp: pass
        newbie = Temp()

can be replaced with

        from types import ObjectType
        newbie = ObjectType()


                    "Alex Martelli"                                                                                
                    <aleaxit at        To:     python-list at                                       
                    >                         cc:                                                                  
                    Sent by:                  Subject:     Re: Copy constructors                                   
                    08/09/01 01:14 PM                                                                              

"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()
        print "very little work"



More information about the Python-list mailing list