less obvious "super"

Francesco Guerrieri f.guerrieri at gmail.com
Mon Sep 10 06:06:03 EDT 2007


On 9/10/07, Nagarajan <naga86 at gmail.com> wrote:
>
> Hi group,
> I am confused with "super" usage..It seems to be complicated and less
> obvious.
> Here is what I need to achieve..
>
> class A :
>     def __init__( self ):
>         self.x  = 0
>
> class B ( A ):
>     def __init__( self, something ):
>         # Use "super" construct here so that I can "inherit" x of A
>         self.y  = something
>
> How should I use "super" so that I could access the variable "x" of A
> in B?
>


You don't need to use super in this case. You just have to remember to
explicitly initialize the classes you are deriving from. In this case,

class B(A):
    def __init__(self, something):
        A.__init__(self)
        self.y = something

bye,
francesco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070910/80a2293e/attachment.html>


More information about the Python-list mailing list