I'm trying to merge two instances of two different classes.
One idea that could work for me is to assign the attributes from class b
to an existing instance of class a
. Normally I would let a
inherit from b
but this is not possible because a
is initialized when b
is still unknown.
Obviously this is a dummy example, but i think it reflects my problem.
class aa:
def __init__(self) -> None:
self.c = 'c'
class bb:
def __init__(self, obj) -> None:
obj.get_c = self.get_c
self.c = 3
@property
def get_c(self):
return self.c
a=aa()
b=bb(a)
Is it possible to copy the method get_c
that it returns a.c
when a.get_c
is called and not whatever value b.c
had whenb
was initialized?
Desired Output:
a.get_c -> 'c'
b.get_c -> 3