> > The question is: How do i move the 'do' method from A to b (resulting
> > in printing "A.do: self.name = b")?
> > I have tried (with a = A() and b B()):
> > B.do = types.MethodType(A.do, b) #Error
> > and stuff like:
> > b.do = a.do
> > b.do()
> > But either i get an error or b.do() prints "A.do: self.name = a", so
> > the self parameter of a.do is stored somehow in the method.
> > In other words, how do i unbind 'do' from a/A and bind it to b (the
> > instance)?
> > Cheers, Lars
> Is there any particular reason you can't just have B be a subclass of
> A? You could do
> b.do = types.MethodType(A.do.im_func, b, B)
> but there's no point in re-inventing the wheel.
Perfect, Thank you,
As to the why, to make a long story short, actually instantiation
would fit better conceptually than inheritance in this case, but that
would mean the 'A' instances would be types, which introduces
metaclasses, which i tried but i ran into problems with e.g. pickle
and with complexity.