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 trialJordan Paul
2,744 PointsPython OOP: super() challenge tasks
Hi,
I've watched the videos over and over to try to understand how super() works, but I still can't really grasp what it does or what it means to override a method with it. I feel pretty stuck. Help!
Jordan
class Inventory:
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory):
def __init__(self, **kwargs):
pass
2 Answers
Jordan Paul
2,744 PointsThanks for your quick reply.
I think I still don't understand the interaction of classes and subclasses, overriding methods, or using super() and I'll have to look for more resources elsewhere to finish this course.
I'd be surprised if I'm the only one who feels this way, but I think this unit leaves a lot to be desired in terms of beginner-level explanation, pacing and practice. I've watched each of these videos multiple times and I don't understand the concepts any better. Too bad because previous units (especially the intro) have mostly been very well-taught and provided good opportunities for practice.
nakalkucing
12,964 PointsNp! :) Happy coding!
nakalkucing
12,964 PointsHey Jordan Paul! I tried your code in the challenge and it passes the first task. But the second task asks you to:
override the add_item method. Use super() in it to make sure the item still gets added to the list.
You appear to be trying to override the init method.
Let me know if this does/doesn't help. OK? Thanks :)
Have you read the Teacher's Notes for the previous video Super-Duper? These may help you understand how super() works. Kenneth also links to a Blog about super() in the notes for this video. Hope this helps! :)
Jordan Paul
2,744 PointsJordan Paul
2,744 PointsThis is the task: "I've made you a super-simple Inventory class that would let someone store items in it. Not the most useful class, but we'll build something better in a few videos.
For now, though, I need you to create a new class, SortedInventory that should be a subclass of Inventory.
You can just put pass in the body of your class for this step."