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


Groups > comp.lang.python > #13238

Re: Invoke a superclass method from a subclass constructor

References (1 earlier) <4E6C9044.5060302@jollybox.de> <CAPbrmCua4wZFJEyiTJHe5Wo_+ho_Q=F-GRsYvSs_FqEdNTP_Xw@mail.gmail.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F16B197E2@EMARC112VS01.exchad.jpmchase.net> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F16B1987A@EMARC112VS01.exchad.jpmchase.net> <CAPbrmCtEemgxBC1RRjFSmuePsp8AkO8FTO95orJ_T3MMB=j3Og@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-09-13 11:24 -0600
Subject Re: Invoke a superclass method from a subclass constructor
Newsgroups comp.lang.python
Message-ID <mailman.1080.1315934926.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Sep 13, 2011 at 10:56 AM, Kayode Odeyemi <dreyemi@gmail.com> wrote:
>>>> class B(A):
> ...     def __init__(self, module):
> ...             self.module = A.log(self, module)
> ...             print self.module # printing here is completely unnecessary
> in a good OOP language
> ...
>>>> c = B('system')
> logged
>>>> class B(A):
> ...     def __init__(self, module):
> ...             print super(B, self).log('system') # printing here is
> completely unnecessary in a good OOP language
> ...
>>>> c = B('system')
> logged
>>>>
> When an instance of a class is created, all codes within that instance block
> should be executed. That's my understanding of OOP.

The initializer should be executed, which is what Python does.  Your
initializer then calls A.log, which does nothing interesting at all.

My question is, what exactly is it that you intend A.log to do?  As
written, it does not do any logging.  It merely constructs a string
and then returns it.  Neither constructing a string, nor returning a
string, imply logging it or printing it.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Invoke a superclass method from a subclass constructor Ian Kelly <ian.g.kelly@gmail.com> - 2011-09-13 11:24 -0600

csiph-web