initializing cooperative method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jelle

    initializing cooperative method

    Hi,

    I'm writing a bunch of abstract classes and I'd like to delegate the
    arguments of the concrete class the to abstract one. I was surprised
    to see that the print statement in the abstract class isn't executed.
    But moreover, I'd like to find out an idiom that allows one to
    delegate arguments in the inherited class. Any ideas?

    Thanks,

    -jelle



    class Abstract(object ):
    def __init__(self, a='a', b='b'):
    self.a, self.b = a, b
    print a, b

    class Concrete(Abstra ct):
    def __init__(self, a='AAA', b='BBB'):
    super(Abstract, self).__init__( a=a, b=b )
    print a, b

    c = Concrete(a=1)
    >>c = Concrete(a=1)
    1 BBB

  • Steven D'Aprano

    #2
    Re: initializing cooperative method

    On Thu, 06 Sep 2007 16:12:11 +0000, jelle wrote:
    Hi,
    >
    I'm writing a bunch of abstract classes and I'd like to delegate the
    arguments of the concrete class the to abstract one. I was surprised to
    see that the print statement in the abstract class isn't executed. But
    moreover, I'd like to find out an idiom that allows one to delegate
    arguments in the inherited class. Any ideas?
    Change the call to super() in Concrete from:

    super(Abstract, self).__init__( a, b)

    to

    super(Concrete, self).__init__( a, b)



    --
    Steven.

    Comment

    • jelle

      #3
      Re: initializing cooperative method

      Ai, calling super(Abstract) is just getting object, sure...

      However, I'm still curious to know if there's a good idiom for
      repeating the argument in __init__ for the super(Concrete,
      self).__init__ ?

      Thanks,

      -jelle

      Comment

      • jelle

        #4
        Re: initializing cooperative method

        Ai, calling super(Abstract) is just getting object, sure...

        However, I'm still curious to know if there's a good idiom for
        repeating the argument in __init__ for the super(Concrete,
        self).__init__ ?

        Thanks,

        -jelle

        Comment

        • Jonathan Gardner

          #5
          Re: initializing cooperative method

          On Sep 6, 11:18 am, jelle <jelleferi...@g mail.comwrote:
          Ai, calling super(Abstract) is just getting object, sure...
          >
          However, I'm still curious to know if there's a good idiom for
          repeating the argument in __init__ for the super(Concrete,
          self).__init__ ?
          >
          If you don't know what the arguments are, you can use *args and
          **kwargs.

          class Concrete(Abstra ct):
          def __init__(self, *args, **kwargs):
          super(Concrete, self).__init__( *args, **kwargs)


          Comment

          Working...