New inited instance of class?
Francis Avila
francisgavila at yahoo.com
Sat Dec 6 22:51:47 EST 2003
Samuel Kleiner wrote in message ...
>Is there a builtin way of making making another instance of your own
>class?
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