Reputation: 21
Someone can help me to correct this error ? thanks (I'm trying to access a variable in the mother class in the daughter class)
class Animal:
def __init__(self, name):
self.name = name
class Mammal:
def Presentation(self):
print(self.name + "is a mammal")
dog = Animal("Dog")
dog.Mammal.Presentation()
Traceback (most recent call last): File "", line 11, in TypeError: Presentation() missing 1 required positional argument: 'self1'
Upvotes: 1
Views: 1650
Reputation: 117
Not the actual answer to your question, but I guess you want to do something like this:
class Animal:
def __init__(self, name):
self.name = name
def Presentation(self):
raise NotImplementedError
class Mammal(Animal):
def Presentation(self):
print(self.name + "is a mammal")
dog = Mammal("Dog")
dog.Presentation()
Upvotes: 3
Reputation: 4670
The child class would have to inherit the parent self attribute to do that.
class Animal:
def __init__(self, name):
self.name = name
class Mammal:
def Presentation(inherit):
print(inherit.name + “is a mammal”)
dog = Animal("Dog")
Animal.Mammal.Presentation(dog)
Upvotes: -1