Paul Melos2,665 Points
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.