Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #13122 > unrolled thread

Re: Invoke a superclass method from a subclass constructor

Started byDave Angel <davea@ieee.org>
First post2011-09-11 07:55 -0400
Last post2011-09-11 07:55 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Invoke a superclass method from a subclass constructor Dave Angel <davea@ieee.org> - 2011-09-11 07:55 -0400

#13122 — Re: Invoke a superclass method from a subclass constructor

FromDave Angel <davea@ieee.org>
Date2011-09-11 07:55 -0400
SubjectRe: Invoke a superclass method from a subclass constructor
Message-ID<mailman.982.1315742183.27778.python-list@python.org>
On 01/-10/-28163 02:59 PM, Kayode Odeyemi wrote:
> Hello friends,
>
> An instance of my subclass doesn't invoke its superclass method, except when
> it is referenced
> directly.
>
> Here is what I mean:
>
>>>> 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')
>>>> # I expect 'logged' to be printed here
>>>> print c.log('system') # why do I have to do this?
>>>> 'logged'
> Why do I have to make a call to c.log before log() method can be invoked?
>
> My reasoning is such that since I have passed the log() method to B's
> constructor, an instance
> of B should invoke A's log() method.
>
> What could I be missing in class A or B to have this working as expected?
What makes you think that A.log() was not invoked???

You have no print statement, so you can't tell that way.  All the method 
does is to modify a temporary object of type A, so you can't tell that way.

Perhaps you mean to write
       self.module = A.log(self, module)

So that the return value could do some good.

DaveA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web