weboykal weboykal - 1 month ago 11
Python Question

<main.Handyman object at 0x01CB8D30>

So, I see that some other people have encountered the same issue as me. But the answers they got didn't relate to/fix the problem I'm having.

class Player:
def __init__(self, length=2.1, health=10):
self.length = length
self.health = health

def __str__(self):
return "{} long and has {} health.".format(self.length, self.health)

class Handyman(Player):
def __init__(self):
super().__init__(length=1.9, health=7)

Handy = Handyman()

print("Handymans stats are:")
print(Handy)


But when I try to print "Handyman", I end up with this: main.Handyman object at 0x01CB8D30.
I tried printing Handyman(), Handy() and so on, but nothing fixed it. I feel like people will get frustrated because this is easily fixed somehow, but posting here was my last resort.

Answer

Indentation matters in Python. Fixed code is:

class Player:
    def __init__(self, length=2.1, health=10):
        self.length = length
        self.health = health

    def __str__(self):
        return "{} long and has {} health.".format(self.length, self.health)

class Handyman(Player):
    def __init__(self):
        super().__init__(length=1.9, health=7)

Handy = Handyman()

print("Handymans stats are:")
print(Handy)
Comments