New inited instance of class?

Francis Avila francisgavila at
Sun Dec 7 04:51:47 CET 2003

Samuel Kleiner wrote in message ...
>Is there a builtin way of making making another instance of your own

You mean, from the inside (from one of the instance methods of the class)?

def new(self, *args, **kargs):
    return self.__class__(*args, **kargs)

>I really expected type(self)(*args, **keywords) to work this way.

Works for me.  What traceback does it give you?

>Currently i'm doing this:
>def new(self,*args,**keywords):
>        from new import instance
>        s=instance(self.__class__)
>        if hasattr(D(),'__init__'):
>            s.__init__(*args,**keywords)
>        return s

That's ugly.

Francis Avila

More information about the Python-list mailing list