Invoke a superclass method from a subclass constructor
Kayode Odeyemi
dreyemi at gmail.com
Sun Sep 11 04:18:29 EDT 2011
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?
--
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110911/198c8789/attachment.html>
More information about the Python-list
mailing list