[Tutor] Challenge supporting custom deepcopy with inheritance

Alan Gauld alan.gauld at btinternet.com
Mon Jun 1 22:55:38 CEST 2009

"W W" <srilyk at gmail.com> wrote
>> class C:
>>    @constructor
>>    def LoadFromFile(fname, count): ...
>>    @constructor
>>    def Create(valueTuple):...
>> Personally I prefer the Delphi style sincve it makes the constructor
>> call explicit and adds to the documentation.
>> Alan G
> That does make it problematic... although I suppose checking the type 
> would
> be a workaround - still, not simple or beautiful. Has this been 
> introduced
> as a PEP?

Type checking is the problem. Until Python can distinguish methods based
on types (which introduces other issues)  thisi is difficult with the 
C/Java style.

We can fake the Delphi style by using a default constructor and then just
calling the "constructors" after initialisation:

class C:
         def __init__(): pass
        def LoadFromFile(fname, count): ...
       def Create(valueTuple):...

c = C()
c.LoadFromFile(fn, cnt)

But its two lines not one... :-(

And so far as I know it has not been PEPd although I'm sure it has
been discussed.

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list