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 trialThomas Wilhelm
3,714 PointsYour 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!
class Student:
name = "Tom"
def praise(self):
print("You're doing a great job, {}".format(name))
1 Answer
Thomas Wilhelm
3,714 PointsHi 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?
Rohald van Merode
Treehouse StaffRohald van Merode
Treehouse StaffHi Thomas,
You have to return from the function. I got it working with the following code:
Hope that helped