Invoke a superclass method from a subclass constructor

Kayode Odeyemi dreyemi at gmail.com
Tue Sep 13 12:56:55 EDT 2011


On Tue, Sep 13, 2011 at 5:46 PM, Prasad, Ramit <ramit.prasad at jpmorgan.com>wrote:

> >You should be passed super the current class you want the super class of,
> not the type of the super class. So it should be:****
>
> >super(*B*, self).log('system') # Notice that it passed class B****
>
> ** **
>
> Ugh, apologies for the poor English; my tea has not kicked in.****
>
> ** **
>
> That first line would be more understandable as:  ‘You should pass the
> current class (B) you want the super class of, not the type of the super
> class (A) itself. So it should be:’****
>
> ** **
>
> To clarify, by passing A to super it retrieves the definition for the base
> class (object) which does not have the function you are trying to access.*
> ***
>
> ** **
>
> Ramit
>

Thanks for helping me clarify on how to use super() in Py2+. That really
worked!

>>> 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.

Thanks everyone!


> ****
>
> ** **
>
> ** **
>
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology****
>
> 712 Main Street | Houston, TX 77002****
>
> work phone: 713 - 216 - 5423****
>
> ****
>
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of securities,
> accuracy and completeness of information, viruses, confidentiality, legal
> privilege, and legal entity disclaimers, available at
> http://www.jpmorgan.com/pages/disclosures/email.
>



-- 
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/20110913/8bd70693/attachment-0001.html>


More information about the Python-list mailing list