Initializing a subclass with a super object?

Discussion in 'Python' started by frankdmartinez@gmail.com, May 11, 2008.

  1. Guest

    Class A inherits from class B. Can anyone point me in the direction
    of documentation saying how to initialize an object of A, a1, with an
    object of B, b1?
     
    , May 11, 2008
    #1
    1. Advertising

  2. Terry Guest

    On May 11, 7:22 am, wrote:
    > Class A inherits from class B. Can anyone point me in the direction
    > of documentation saying how to initialize an object of A, a1, with an
    > object of B, b1?


    This is called a 'factory'in design patterns. Search 'python factory',
    you will get a lot of examples.

    br, Terry
     
    Terry, May 11, 2008
    #2
    1. Advertising

  3. Guest

    Hi, Terry.
    Yeah, no. If we think of the inherited B as an object nested
    within a1, I'm attempting to initialize that B with b1 by accessing
    the B, say, via a function call. I don't see how using a python
    factory achieves this.
     
    , May 11, 2008
    #3
  4. Guest

    On May 11, 3:19 am, Francesco Bochicchio <> wrote:
    > But there is not such a thing, in Python. What you have is that A
    > has the same attributes/methods of B plus its own.
    > What you could do is  adding in class A a method like this:
    >
    >   class A(B):
    >      ...
    >      def set_b_attributes(self, instance_of_b):
    >          for k, value in instance_of_b.__dict__:
    >                 setattr(self, k, value )
    >
    > and the use it like this:
    >
    >    a1.set_b_attributes(b1)


    Hi, Francesco.
    Thanx! That's actually exactly what I needed (though I didn't
    know it).
     
    , May 12, 2008
    #4
    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. Guest

    super.super.super how?

    Guest, Feb 19, 2005, in forum: Java
    Replies:
    24
    Views:
    10,799
    Darryl Pierce
    Feb 24, 2005
  2. jstorta
    Replies:
    3
    Views:
    449
    jstorta
    Feb 20, 2006
  3. S.Volkov
    Replies:
    2
    Views:
    222
    S.Volkov
    Mar 12, 2006
  4. Trans
    Replies:
    8
    Views:
    324
    Robert Klemme
    Oct 23, 2008
  5. Fab

    Subclass of subclass

    Fab, Aug 9, 2012, in forum: C++
    Replies:
    0
    Views:
    399
Loading...

Share This Page