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

Python Object-Oriented Python Instant Objects Your first method

Getting a "NameError." What am I missing?

I seem to be following the instructions for this task, but it keeps saying that I have a NameError where it says "name" is not defined. I thought it was already defined as an attribute. If anyone can help me see what I'm missing here, please let me know. Thank you.

first_class.py
class Student:
    name = "Michael"

    def praise(self):
        return print("You're doing a great job, {}!".format(name))

1 Answer

Elisa Burghard
Elisa Burghard
9,276 Points

Hi Michael, you are very close!

class Student:
    name = "Michael"

    def praise(self):
        return ("You're doing a great job, {}!".format(self.name))

You pass the praise method an argument (self), in which you then call .format(name), it does not know which name you are referring you. Also the text above states return and not to print it on the screen. The devil's in the detail sometimes ;) Keep up the good work and happy coding!

Hello Elisa,

Thank you for getting back to me. Modified my code as you recommended, and made note of it for reference later. I appreciate your assistance.