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 trialJonathan Fanno
52 PointsAttributeError: 'Student' object has no attribute 'praise'
Why is it asking me for an attribute called praise, when the assignment was simply to create a method that would return a message? I entered this code into my own IDE, Pycharm and it works.
class Student:
name = "Jonathan"
def Praise(self):
return "You'll get there"
me = Student()
print(me.Praise())
1 Answer
Steven Tagawa
Python Development Techdegree Graduate 14,438 PointsTo me this looks like a quirk of the challenge evaluator. The way I understand it, when you do a code challenge, what you write gets passed to an interpreter that isn't full-blooded Python, so sometimes little glitches happen. Your code is technically correct, which is why it works in PyCharm: me.Praise()
runs the Praise
method of your Student
object, and then the print()
prints the value the method returns. But it looks like the evaluator is trying to interpret the dot-notation as trying to access a Praise
attribute in your Student
class, and then throwing an error because it doesn't exist. (It totally shouldn't be doing this, especially because of the trailing parentheses, which no attribute call would have.
If you'd written print(me.Praise)
-- without the parentheses -- then it would be a call to print an attribute value.)
Probably the easiest way to "fix" it (again, not because it's wrong, but just to get something the evaluator will accept) is to break it into two steps: assign the return value of me.Praise()
to a variable, and then print the variable.