Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
What does Kenneth mean that you can't set sneaky?
He says in the video that we've lost the ability to set sneaky...
Since Character class accepts kwargs, wouldn't you just pass it when you initialize a thief object??
obj = Thief("bill", sneaky=True)
import random class Character: def __init__(self, name, **kwargs): self.name = name for key, value in kwargs.items(): setattr(self, key, value) class Thief(Character): sneaky = True def pickpocket(self): return self.sneaky and bool(random.randint(0, 1)) def hide(self, light_level): return self.sneaky and light_level < 10
We want the Thief to have sneaky as an ability as standard rather than using it as an add on using **kwargs.
In the same way if we decided to create a class for a Knight character you could have sword as standard when creating the Knight and not need to add sword using kwargs.
obj = Knight("Arthur", "Excalibur")
obj = Knight("Arthur", sword="Excalibur")
I hope that makes sense like it does in my head :)
Hi Paul. Yes, I'm still figuring super() and OOP out myself, but you're correct -- by using super() when we initialize a Thief() or a Knight(), we reduce written code. After all, all characters have the ordinary character attributes, including name. But not all characters have a sneaky attribute, or a sword/Excalibur attribute. I think Christopher's example is a good one.