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

Your First Method Help!

I'm getting a NameError: name isn't defined.

I don't know why the method isn't referencing the attribute. Wouldn't the attribute act like a "Global" attribute within the class so the method could access it?

I tried a few different ways in the workspace but I can't really get it. I did get the proper response in the python interpreter but it doesn't translate over...

Please assist! Thank you!

first_class.py
class Student:
    name = "Tom"

    def praise(self):
        print("You're doing a great job, {}".format(name))
Rohald van Merode
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rohald van Merode
Treehouse Staff

Hi Thomas,

You have to return from the function. I got it working with the following code:

class Student:
    name = "Your Name"

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

Hope that helped

1 Answer

Hi Rohald!

I also did tried the return in the method...what I think I missed was the

format(self.name)

What does the self part do, exactly? Does it call the class that it's in?