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!

Frances Angulo
Frances Angulo
5,311 Points

override and super()

I thought I was already overriding the add_item method, now I'm completely lost as to what to do next.

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

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

class SortedInventory(Inventory): 

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

3 Answers

Steven Parker
Steven Parker
231,271 Points

There's no override for "add_item" here, but instead there is an override for "__init__" (which is not needed).

I see "add_item" being passed as an argument but that also isn't needed for this challenge.

Steven Parker
Steven Parker
231,271 Points

You're kind of close, just change "init" to "add_item" and leave off the extra argument.

Why is this not working for me? Lol. I used the same code and changed "init" to "add_item" but I still get a Try Again.

Steven Parker
Steven Parker
231,271 Points

Did you change it in both places?

Frances Angulo
Frances Angulo
5,311 Points

I had to start the entire OO section over to get this right and I am still not sure how I got to the right answer. Woof.

Frances Angulo
Frances Angulo
5,311 Points

Yeah I got there I just had to go back and re-watch from the beginning of the OO course and then give a few swings at the answer... still only 60-70% there in terms of understanding.

Any plans for a TechDegree that covers this content?

Steven Parker
Steven Parker
231,271 Points

Isn't this course already part of the Techdegree program?

Anyway, glad I could help. Happy coding!