Returning another instance from constructor
From: Edward Diener (eldiener_at_earthlink.net)
Date: 07/31/04
- Next message: Edward Diener: "Comments within a line"
- Previous message: Christopher T King: "Re: Easy way to remove HTML entities from an HTML document?"
- Next in thread: Robert Brewer: "RE: Returning another instance from constructor"
- Maybe reply: Robert Brewer: "RE: Returning another instance from constructor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 31 Jul 2004 02:03:49 GMT
Is there a way in Python to have the constructor of a class "return" another
instance of the same class ? I am well aware of the fact that __init__ does
not return anything, but I would love to do something like this:
class X(object):
def __init__(self,...other parameters):
# some magic code
x = X()
y = X()
and have y actually referencing x automatically.
Of course I am aware that if X is passed an optional parameter of type X in
its constructor, it can forward all its member functions to that other X.
But I am looking for something even more magical. I thought that maybe I
could do such magic using metaclasses, but metaclasses only create classes
and not class instances, so I do not see how. If anyone has any ideas I
would love to hear it.
- Next message: Edward Diener: "Comments within a line"
- Previous message: Christopher T King: "Re: Easy way to remove HTML entities from an HTML document?"
- Next in thread: Robert Brewer: "RE: Returning another instance from constructor"
- Maybe reply: Robert Brewer: "RE: Returning another instance from constructor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|