Copy constructors
David Smith
drs at labs.agilent.com
Thu Aug 9 14:55:54 EDT 2001
It appears that the preferred way to make a copy constructor is to
define the __copy__ method. In the examples I have seen, __copy__ then
creates a new object in the usual way, which invokes __init__. In a
class I have at hand, __init__ does some real work, which I want to
bypass -- I want to clone the results of that work. I don't want to
redefine __init__'s parameter list (to permit passing only one parameter
of the same class), because it would screw up IDLE's automatic parameter
list prompting.
Is there a way for __copy__ to create a bare object of the same class,
which it can proceed to populate?
David Smith
More information about the Python-list
mailing list