[Tutor] Challenge supporting custom deepcopy with inheritance

Kent Johnson kent37 at tds.net
Mon Jun 1 23:35:12 CEST 2009


On Mon, Jun 1, 2009 at 4:55 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:

> We can fake the Delphi style by using a default constructor and then just
> calling the "constructors" after initialisation:
>
> class C:
>        def __init__(): pass
>       @constructor
>       def LoadFromFile(fname, count): ...
>      @constructor
>      def Create(valueTuple):...
>
> c = C()
> c.LoadFromFile(fn, cnt)
>
> But its two lines not one... :-(

Why not this?

class C:
  def __init__(self): pass

  @staticmethod
  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)

Kent


More information about the Tutor mailing list