Method returning new instance of class?
aleaxit at yahoo.com
Sun Sep 5 18:41:03 CEST 2004
Arthur <ajsiegel at optonline.com> wrote:
> A bit inspired by the decorator discussions, I'm trying to tackle something
> I had been avoiding.
> Essentially I am trying to create a non-destructive tranformation of an
> instance of a class - is one way of putting it.
> The way I am currently conceptualizing a solution, what I need is a method
> of the class that returns a new instance of the class.
theclass.__new__(theclass, *args, **kwds)
is one way to return a new instance of class theclass, which will
typically be empty (unless theclass's instances are immutable, since, in
that case, __new__ must do the initializaiton work... because it would
be too late by __init__ time).
Not clear if it's what you need, but it seems to be what you ask for.
More information about the Python-list