Re: Newbie inheritance question.

Discussion in 'Python' started by Ed Leafe, Jan 16, 2005.

  1. Ed Leafe

    Ed Leafe Guest

    On Jan 16, 2005, at 9:08 AM, bwobbones wrote:

    > class two(one):
    > def __init__(self):
    > print "two"


    You need to specifically call the superclass's __init__ here in order
    for it to fire. Just add the line

    super(two, self).__init__()

    as the first line of the subclass's __init__.

    ___/
    /
    __/
    /
    ____/
    Ed Leafe
    http://leafe.com/
    http://dabodev.com/
    Ed Leafe, Jan 16, 2005
    #1
    1. Advertising

  2. Ed Leafe wrote:
    > On Jan 16, 2005, at 9:08 AM, bwobbones wrote:
    >
    >> class two(one):
    >> def __init__(self):
    >> print "two"

    >
    > You need to specifically call the superclass's __init__ here in order
    > for it to fire. Just add the line
    >
    > super(two, self).__init__()
    >
    > as the first line of the subclass's __init__.


    For that, he must use new-style classes:

    -class one:
    +class one(object):


    Reinhold
    Reinhold Birkenfeld, Jan 16, 2005
    #2
    1. Advertising

  3. Ed Leafe

    Just Guest

    In article <>,
    Ed Leafe <> wrote:

    > On Jan 16, 2005, at 9:08 AM, bwobbones wrote:
    >
    > > class two(one):
    > > def __init__(self):
    > > print "two"

    >
    > You need to specifically call the superclass's __init__ here in order
    > for it to fire. Just add the line
    >
    > super(two, self).__init__()
    >
    > as the first line of the subclass's __init__.


    super() only works for new-style classes, ie. class one needs to derive
    from object for this to work.

    Just
    Just, Jan 16, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maxw_cc
    Replies:
    1
    Views:
    3,136
    Martijn van Steenbergen
    Dec 21, 2003
  2. cppsks
    Replies:
    0
    Views:
    815
    cppsks
    Oct 27, 2004
  3. karthikbalaguru
    Replies:
    9
    Views:
    1,036
  4. Daniel Pitts
    Replies:
    27
    Views:
    1,896
    Mike Schilling
    Feb 27, 2008
  5. johnsonlau
    Replies:
    1
    Views:
    769
    Kai-Uwe Bux
    Jul 21, 2008
Loading...

Share This Page