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 trialDaniel Lounsbury
1,744 Pointssetattr expected 3 arguments, got 2
I have been getting "Bummer: Exception: setattr expected 3 arguments, got 2"
I am a bit lost as to how to add a third argument to this code
class Student:
name = "Shawn"
def __init__(self, name = name, **kwargs):
self.name = name
for key, value in kwargs.items():
setattr(self, name,)
shawn = Student(name='shawn', major='chemistry', likes_coding=True, year=2)
def praise(self):
return "You inspire me, {}".format(self.name)
def reassurance(self):
return "Chin up, {}. You'll get it next time!".format(self.name)
def feedback(self, grade):
if grade > 50:
return self.praise()
return self.reassurance()
3 Answers
Jeff Muday
Treehouse Moderator 28,720 PointsNote-- you introduced an infinite loop with this line marked below. dunder init keeps instantiating a student named 'shawn' recursively.
class Student:
name = "Shawn"
def __init__(self, name = name, **kwargs):
self.name = name
for key, value in kwargs.items():
setattr(self, key, value)
# GET RID OF THIS LINE BELOW,-- MOVE IT OUTSIDE OF OBJECT IT IS NESTED INSIDE DUNDER INIT
shawn = Student(name='shawn', major='chemistry', likes_coding=True, year=2)
Jeff Muday
Treehouse Moderator 28,720 PointsYour're so close!
for key, value in kwargs.items():
setattr(self, name,)
should be
for key, value in kwargs.items():
setattr(self, key, value)
Daniel Lounsbury
1,744 PointsI tried that and it returned the following error: "Exception: maximum recursion depth exceeded while calling a Python object"
Jeff Muday
Treehouse Moderator 28,720 PointsIf you haven't already done so, I'd totally recommend installing a good programming IDE (Integrated Development Environment). These can really increase productivity and catch the Homer Simpson 'DOH!' moments before they happen.
There are three IDEs worth mentioning because these are multiplatform (e.g. run on Mac, PC, or Linux)--
I am a fan of Wingware (I use the Pro version, but Personal has all the features an aspiring developer would want and it's free for personal use); PyCharm EDU is exceptionally strong and gives lots of PEP-8 hints; and the new kid on the block Visual Studio Code (though it takes a little more effort to configure), is a strong contender as well -- quite a bit faster than PyCharm in my opinion.
Daniel Lounsbury
1,744 PointsDaniel Lounsbury
1,744 PointsYou Sir are a gentleman and a scholar.