Method returning new instance of class?
Alex Martelli
aleaxit at yahoo.com
Sun Sep 5 12:41:03 EDT 2004
More information about the Python-list mailing list
Sun Sep 5 12:41:03 EDT 2004
- Previous message (by thread): Method returning new instance of class?
- Next message (by thread): Method returning new instance of class?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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. Alex
- Previous message (by thread): Method returning new instance of class?
- Next message (by thread): Method returning new instance of class?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list