[Tutor] Challenge supporting custom deepcopy with inheritance
alan.gauld at btinternet.com
Tue Jun 2 01:48:10 CEST 2009
"Kent Johnson" <kent37 at tds.net> wrote
> > We can fake the Delphi style by using a default constructor and then
> > just
> > calling the "constructors" after initialisation:
> > But its two lines not one... :-(
> Why not this?
> class C:
> def __init__(self): pass
> def LoadFromFile(fname, count):
> c = C()
> # init c from the file
> return c
> and similar for Create(). Client code is one line:
> c = C.LoadFromFile(fn, cnt)
Why not indeed?! I must remember that pattern for future reference.
Wish I'd thought of it a few months ago when I was wrestling with a
problem that could have used multiple constructors!
More information about the Tutor