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 trialdmitriy ignatiev
Python Web Development Techdegree Student 1,789 PointsInheritance in python
Hi, try to create a new monster DDD = Monster(color = 'red', adjective = 'jfdhg') as it was shown in video and add a new attribute = 'adjective' wich wasn't add in a code but recieved an error. Please clarify why it could happen i can not see any mistakes in my code
AttributeError: 'Monster' object has no attribute 'adject
1 Answer
Chris Howell
Python Web Development Techdegree Graduate 49,702 PointsTo be able to instantiate a Monster object from the Monster class.
Each attribute you pass into the ( ) of Monster() needs to be defined within the Monster class. Does that make sense?
If you watch the video again, pay close attention to what Kenneth does inside this method.
def __init__(self, **kwargs):
Basically to be able to pass in things to Monster like this
goblin = Monster(color='red', adjective='scary')
Both color and adjective have to be defined inside the class which is what Kenneth did inside the init method. :)
Roman Mayer
10,925 PointsRoman Mayer
10,925 PointsThe whole point of this video IMHO is, that you don't need to pre-define all attributes. When you use
in your init, then any attribute can be set during instantiation: