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
Moises Miguel
5,028 PointsWhere is the bug in my code?
class Person: def init(self, **kwargs): self.race = kwargs.get('race', 'Mexican') self.age = kwargs.get('age', 3) self.language = kwargs('language', 'Spanish')
def language(self): return self.language.upper()
I have this file saved as monster.py
first i do this in the shell: python from monster import Person
then i try to get information on the person initial qualities
Person.race()
and i get a:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'Person' has no attribute 'race'
Person.race()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'Person' has no attribute 'race'
it does this for all of the initial traits. How do i fix this??
1 Answer
Alexander Davison
65,469 PointsYou need to put dunders (two underscores __) around init so it looks like this: init This function is pronounced "dunder init".
Moises Miguel
5,028 PointsMoises Miguel
5,028 Pointsclass Person: def init(self, **kwargs): self.race = kwargs.get('race', 'Mexican') self.age = kwargs.get('age', 3) self.language = kwargs('language', 'Spanish')
def language(self): return self.language.upper()
This is my code