Invoke a superclass method from a subclass constructor
Andreas Perstinger
andreas.perstinger at gmx.net
Sun Sep 11 12:47:42 EDT 2011
On 2011-09-11 13:17, Kayode Odeyemi wrote:
> On Sun, Sep 11, 2011 at 11:41 AM, Thomas Jollans<t at jollybox.de> wrote:
>> It is working:
>>
>> >>> class A(object):
>> ... def log (self, module):
>> ... return str ('logged')
>> ...
>> >>> class B(A):
>> ... def __init__(self, module):
>> ... self.module = A().log(module)
>> ...
>> >>> c = B('system')
>> >>> c.module
>> 'logged'
>
> Why do you have to do c.module? I'm expecting an output just by creating an
> instance of B.
Why do you expect an output? In B.__init__ you are just assigning the
return value from A.log() to the attribute "module" and in A.log() there
is no output either.
Bye, Andreas
More information about the Python-list
mailing list