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!

I've made you a super-simple Inventory class that would let someone store items in it. Not the most useful class, but we

.

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

    def add_item(self, item):
        self.slots.append(item



class SortedInvento(Inventory):
        slot = 0

    def add_item(self, item):
        super().add_item(item)
    def __init__(self):
        super().__init__()
        slot.sort()

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Hey jalil damian

So you almost got it! You shouldn't need to override the __init__ method. If you notice the Inventory class has an attribute created in its __init__ method. Since you are inheriting from this Inventory class you auto-magically inherit access to that attribute too. You should be able to access that attribute using self inside the child class (SortedInventory). Kind of like how its being done inside the Inventory class to add an item, except in your SortedInventory class right after you add an item, you need to sort THAT list.

If that makes sense? If not let me know, I will try to elaborate more with examples.

ok tanks