Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Inheritance Super!

joshua korir
joshua korir
1,445 Points

what is wrong with my code

inheritance

inventory.py
class Inventory:
    def __init__(self):
        self.slots = []

    def add_item(self, item):
        self.slots.append(item)
class SortedInventory(Inventory):

    def __init__(self):
        super().__init__()

4 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

You are close. You’ve overridden the __init__ method not the add_item method.

Edit: You can override add_item the same way __init__ was over ridden. Just change the names and be sure to include the item parameter. The first task you’re creating a redundant method to the parent’s method. It’s a needed set up for Task 2.

Edit 2:

  • literally replace __init__ with add_item, in your original code.
  • add item parameter to both the method definition and as an argument to the super call: super().add_item(item)

Post back if you need more help. Good luck!!!

joshua korir
joshua korir
1,445 Points

how is that done? i thought the subclass automatically enables us to access all method s of it parents

joshua korir
joshua korir
1,445 Points

i dont think the video covered this

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

It didn't cover this exact scenario. It requires you to apply the concepts to a slight newer tasks. All of the concepts have been shown, just not this exact task.