less obvious "super"

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Mon Sep 10 07:36:17 EDT 2007


Nagarajan wrote:
> 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?

Since you're neither using new-style classes (inheriting from
object) nor multiple inheritance, better use the classic way:

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

IMHO, you could also benefit from looking at an OO python tutorial
since this is a standard approach.

Regards,


Björn

-- 
BOFH excuse #145:

Flat tire on station wagon with tapes.  ("Never underestimate the
bandwidth of a station wagon full of tapes hurling down the
highway" Andrew S. Tannenbaum) 




More information about the Python-list mailing list