How do I get rid of unneeded parameters in a class initiation?

Viewed 108

So I'm trying to get the hang of OOP in Python. The problem I have is when initializing my objects for sub-classes, I'm still having to input information which I shouldn't need to.

Specifically, I'm trying to make it so I can create a Person object without specifying can_speak. So I could do something like:

John = person("John Anderson")

Without having to input can_speak as part of the initialization.

class Animal(object):
    def __init__(self, name, can_speak):
        self.name = name
        self.can_speak = False

class Dog(Animal):
    pass

class Person(Animal):
    def __init__(self, name, can_speak):
        self.name = name
        self.can_speak = True

Bob = Person("Bob the Builder", 3.141)
print(Bob.name)
print(Bob.can_speak)
# Bob the Builder
# True

Sam = Dog("Sam the Mutt", 0.00059)
print(Sam.name)
print(Sam.can_speak)
# Sam the Mutt
# False

Here I have to put something as the second input into the initialization, or I get an error. It's a waste like this.

3 Answers
Related