Say I have a class A
that holds some basic attributes, ie
class A:
def __init__(self,name,value,):
self.name = name
self.value = value
I want to make a sub-class B
that has all the properties of A
, but also includes additional methods, like
class B(A):
def __init__(self,instance_of_A):
# ???
def add_to_value(self,x):
return self.value + x
Eventually, I want to do something like
a = A('my_name',3)
b = B(a)
c = b.add_to_value(2) # c is 5
print(b.name) # should print 'my_name'
Is there a way to do this without explicitly taking every attribute of a
and giving it to b
when b
is created?