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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![haakon Guttormsen](https://secure.gravatar.com/avatar/b7356990b71071466975060a2d9adb12?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
haakon Guttormsen
2,157 Pointshow to "run" a method within a class?
I want to be able to "run" whats going on within a method of a class. Is there a way to this? I want to run the praise-method below:
class Student:
name = "håkon"
def praise (self):
return ("I like your hair today {}".format(self.name))
Student.praise(self)
1 Answer
![Jeff Muday](https://uploads.teamtreehouse.com/production/profile-photos/5900142/micro_jeff_face.jpg)
Jeff Muday
Treehouse Moderator 28,718 PointsIf you use the '@classmethod' decorator, the code should run the way you described. If you left off the decorator, you cannot execute the praise method directly, but would be required to instantiate the class object, like s=Student() and s.praise()... see below
# here I run command line python
C:\Users\Jeffrey>\Python36\python.exe
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class Student:
... name = "håkon"
... @classmethod
... def praise (self):
... return ("I like your hair today {}".format(self.name))
...
>>> Student.praise()
'I like your hair today håkon'
# without the class method, you can still use the praise method after you instantiate the class object
>>> s = Student()
>>> s.praise()
'I like your hair today håkon'
mhjp
20,372 Pointsmhjp
20,372 PointsYou need to first instantiate an instance of the class. Then call the method.