[Tutor] Inheritance help

Lie Ryan lie.1296 at gmail.com
Wed Jul 2 18:55:34 CEST 2008


> Hi Folks,
> 
> I can redefine the class and I get a "TypeError: __init__() takes
> exactly 1
> argument (2 given)" error.  I'm creating a SinglePeakFit object and
> not a
> FileParse one. Still puzzled...

In this:

class SinglePeakFit(FileParse):
    ...
    def __init___(self, filename):
        print "I am here!"
        super(FileParse,self).__init__()
    ...
...

You called the __init__ of FileParse's superclass(es), i.e.
object.__init__

What you wanted is this:

class SinglePeakFit(FileParse):
    ...
    def __init___(self, filename):
        print "I am here!"
        super(SinglePeakFit,self).__init__()
    ...
...

which calls the superclass(es) of SinglePeakFit, i.e. FileParse.__init__

Anyway, you don't actually need to use super() unless your class use
multiple inheritance. And even the en it is only really required if
there is 'diamond'-shaped inheritance, like: A(object), B(A), C(A), D(A,
B). But it is good practice to use super for any multiple inheritance,
even though it's not diamond shaped (actually all cases of multiple
inheritance is diamond shaped since all (new-style) classes inherits
from object).



More information about the Tutor mailing list