super() woes (n00b)
Deadly Dirk
dirk at pfln.invalid
Fri Jun 18 09:11:41 EDT 2010
On Fri, 18 Jun 2010 11:19:56 +0200, Jean-Michel Pichavant wrote:
> Deadly Dirk wrote:
>> I cannot get right the super() function: Python 3.1.1+ (r311:74480, Nov
>> 2 2009, 14:49:22) [GCC 4.4.1] on linux2
>> Type "copyright", "credits" or "license()" for more information. ====
>> No Subprocess ====
>>
>>>>> class P:
>>>>>
>> def __init__(__class__,self):
>> print("I am a member of class P")
>>
>>
>>
>>>>> class C(P):
>>>>>
>> def __init__(self):
>> super().__init__(self)
>> print("I am a member of class C")
>>
>>
>>
>> class P:
>> def __init__(self):
>> print("I am a member of class P")
>>
>> class C(P):
>> def __init__(self):
>> super().__init__(self)
>> print("I am a member of class C")
>>
>> x=C()
>>
>> That is more or less the text from the "Quick Python Book". What am I
>> doing wrong?
>>
>>
> If you're quite new to Python I would advise to drop super and use an
> explicit call, sounds lame but my guess is that many people do that,
> 'cause explicit >> implicit. Super is meant to solve some issues about
> multi inheritance, especially diamond diagram inheritance. It has no
> benefit for single inheritance.
>
> I'm pretty sure someone will state that understanding super is pretty
> much easy once you've read the documenation but anticipating all the
> underlying concepts may be tricky. The only situation where super is
> absolutely required is when the inheritance diagram is built dynamically
> during execution.
> Otherwise, I would say "Have the nuts to explicit which base class
> method you want to call" (easy for single inheritance though :) )
>
> class C(P):
> def __init__(self):
> P.__init__(self)
>
>
> JM
Jean-Michel, thanks for your advice. I do think that I understand the
"super" function, I used to do some C++ programming and am quite adept at
programming. I am learning Python and, as a stickler for details, I am
testing and running every little piece of code.
--
I don't think, therefore I am not.
More information about the Python-list
mailing list