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

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

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

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. Jon
    Replies:
    1
    Views:
    387
    John Saunders
    Aug 6, 2003
  2. Billy Boy

    Newbie Question on Web Form Inheritance

    Billy Boy, Mar 5, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    423
    Billy Boy
    Mar 6, 2004
  3. Ex_Ottoyuhr
    Replies:
    5
    Views:
    650
    Ex_Ottoyuhr
    Jul 22, 2004
  4. Jeremy Bowers

    Newbie inheritance question.

    Jeremy Bowers, Jan 16, 2005, in forum: Python
    Replies:
    2
    Views:
    310
    Christophe Cavalaria
    Jan 16, 2005
  5. Al
    Replies:
    2
    Views:
    472
  6. Replies:
    5
    Views:
    550
    sumedh.....
    Jul 20, 2007
  7. Replies:
    5
    Views:
    426
  8. Jerry C.
    Replies:
    8
    Views:
    586
    Uri Guttman
    Nov 23, 2003
Loading...