Why my python class not working?

an offer can't refuse

As shown in the code, Dog is a subclass of Pet. When I create an instance of Dog, I can't get the species of it. By the way, I am following this article?

class Pet(object):

    def __init__(self, name, species):
        self.name = name
        self.species = species

    def getName(self):
        return self.name

    def getSpecies(self):
        return self.species

    def __str__(self):
        return "{0} is a {1}".format(self.name, self.species)


class Dog(Pet):

    def __int__(self, name, chaseCats):
        Pet.__init__(self, name, "dog")
        self.chaseCats = chaseCats

    def getChaseCats(self):
        return self.chaseCats

When create an instance:

mister_dog = Dog("Huang ~", True)
print mister_dog.getSpecies()

It returns: True rather than dog.

Keith

It's a typo. The subclass Dog first method is named __int__, rather than __init__. Therefore the initializer is not being defined in the subclass and you are only calling the base class's __init__ directly.

By the way, you could start using the super() method as well, rather than the unbound method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python: Why is my class method not working?

From Dev

Why is the NameError from the set method in my Python class not working?

From Dev

Why is my autoclicker in python not working?

From Dev

Why is my python program not working?

From Dev

Why is my counter in python not working?

From Dev

why is my python if statement is not working

From Dev

Why is the "thirsty" method on my class not working?

From Java

Why is my configuration test class not working?

From Dev

why is my focus pseudo class not working?

From Dev

Overloading << operator for my own class why is this not working?

From Dev

Why does the class container not working in my code?

From Dev

Why my .bb class is not working on input tag?

From Dev

Why is my python installation not working properly?

From Dev

Why do my Python PIL imports not working?

From Dev

Why is "and" operator not working in my python program?

From Dev

Why try/exception method is not working on my python?

From Dev

Why is my Python list iteration not working correctly?

From Dev

Why is my while function not working on Python?

From Dev

Why is my def function in Python not working?

From Dev

Why is my data save not working with pickle on python?

From Dev

Why is my global variable not working? (Python)

From Dev

why python list append not working in my code?

From Dev

Why is my python word counting program not working?

From Dev

Why is my min() function not working in Python

From Dev

Why is my Python nested while loop not working?

From Dev

(Python) Why is my while loop not working?

From Dev

Why is my Second function not working in python

From Dev

Why is my sep argument in python not working

From Dev

Why this python class is not working with numba jitclass?

Related Related

  1. 1

    Python: Why is my class method not working?

  2. 2

    Why is the NameError from the set method in my Python class not working?

  3. 3

    Why is my autoclicker in python not working?

  4. 4

    Why is my python program not working?

  5. 5

    Why is my counter in python not working?

  6. 6

    why is my python if statement is not working

  7. 7

    Why is the "thirsty" method on my class not working?

  8. 8

    Why is my configuration test class not working?

  9. 9

    why is my focus pseudo class not working?

  10. 10

    Overloading << operator for my own class why is this not working?

  11. 11

    Why does the class container not working in my code?

  12. 12

    Why my .bb class is not working on input tag?

  13. 13

    Why is my python installation not working properly?

  14. 14

    Why do my Python PIL imports not working?

  15. 15

    Why is "and" operator not working in my python program?

  16. 16

    Why try/exception method is not working on my python?

  17. 17

    Why is my Python list iteration not working correctly?

  18. 18

    Why is my while function not working on Python?

  19. 19

    Why is my def function in Python not working?

  20. 20

    Why is my data save not working with pickle on python?

  21. 21

    Why is my global variable not working? (Python)

  22. 22

    why python list append not working in my code?

  23. 23

    Why is my python word counting program not working?

  24. 24

    Why is my min() function not working in Python

  25. 25

    Why is my Python nested while loop not working?

  26. 26

    (Python) Why is my while loop not working?

  27. 27

    Why is my Second function not working in python

  28. 28

    Why is my sep argument in python not working

  29. 29

    Why this python class is not working with numba jitclass?

HotTag

Archive